/* ========================================
   CSS Variables / Theme System
   ======================================== */
:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --navbar-height: 64px;
  --container-max: 1200px;
  --border-radius: 12px;
  --border-radius-sm: 8px;
  --border-radius-lg: 16px;
  --transition: 0.2s ease;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* Dark theme (default) */
[data-theme="dark"] {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1b26;
  --bg-card: #1e1f2e;
  --bg-card-hover: #252636;
  --bg-input: #24253a;
  --bg-overlay: rgba(0, 0, 0, 0.7);
  --text-primary: #e1e2e8;
  --text-secondary: #a1a4b0;
  --text-muted: #6b6e7a;
  --border-color: #2a2b3d;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-bg: rgba(233, 69, 96, 0.1);
  --success: #4caf50;
  --success-bg: rgba(76, 175, 80, 0.1);
  --warning: #ff9800;
  --danger: #f44336;
  --danger-bg: rgba(244, 67, 54, 0.1);
  --navbar-bg: rgba(15, 17, 23, 0.9);
  --scrollbar-track: #1a1b26;
  --scrollbar-thumb: #3a3b4d;
  --card-border: 1px solid var(--border-color);
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #f5f6fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f1f5;
  --bg-input: #f0f1f5;
  --bg-overlay: rgba(0, 0, 0, 0.5);
  --text-primary: #1a1b2e;
  --text-secondary: #5a5c6e;
  --text-muted: #9a9caa;
  --border-color: #e2e3ea;
  --accent: #e94560;
  --accent-hover: #d63050;
  --accent-bg: rgba(233, 69, 96, 0.08);
  --success: #388e3c;
  --success-bg: rgba(56, 142, 60, 0.08);
  --warning: #f57c00;
  --danger: #d32f2f;
  --danger-bg: rgba(211, 47, 47, 0.08);
  --navbar-bg: rgba(255, 255, 255, 0.9);
  --scrollbar-track: #f0f1f5;
  --scrollbar-thumb: #c0c1cc;
  --card-border: 1px solid var(--border-color);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a:hover {
  color: var(--accent-hover);
}

img {
  display: block;
  max-width: 100%;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ========================================
   Utilities
   ======================================== */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

.hidden {
  display: none !important;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto;
}

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

.error-message {
  color: var(--danger);
  padding: 20px;
  text-align: center;
}

.empty-message {
  color: var(--text-muted);
  padding: 40px 20px;
  text-align: center;
}

/* ========================================
   Navbar
   ======================================== */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navbar-height);
  background: var(--navbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: var(--card-border);
  z-index: 100;
}

.navbar-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
}

.navbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
}

.navbar-logo i {
  color: var(--accent);
  font-size: 24px;
}

.navbar-logo:hover {
  color: var(--text-primary);
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  color: var(--text-secondary);
  border-radius: var(--border-radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text-primary);
  background: var(--accent-bg);
}

.badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  line-height: 1.4;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--border-radius-sm);
  font-size: 16px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

/* Mobile Menu */
.mobile-only {
  display: none;
}

.mobile-menu {
  position: fixed;
  top: var(--navbar-height);
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-bottom: var(--card-border);
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 99;
}

.mobile-menu-link {
  padding: 12px 16px;
  color: var(--text-secondary);
  border-radius: var(--border-radius-sm);
  font-weight: 500;
  transition: all var(--transition);
}

.mobile-menu-link:hover {
  background: var(--accent-bg);
  color: var(--text-primary);
}

/* ========================================
   Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.3);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: var(--card-border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid transparent;
}

.btn-danger:hover {
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

/* ========================================
   Main Content
   ======================================== */
.main-content {
  margin-top: var(--navbar-height);
  min-height: calc(100vh - var(--navbar-height));
}

.page {
  padding: 40px 0;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-title i {
  color: var(--accent);
  font-size: 24px;
}

.page-count {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: auto;
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 24px;
}

/* ========================================
   Movie Sections (Home page)
   ======================================== */
.movie-section {
  padding: 20px 0;
}

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

.section-title {
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title i {
  color: var(--accent);
}

.section-link {
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-link:hover {
  color: var(--accent);
}

.section-loading {
  display: flex;
  justify-content: center;
  min-height: 200px;
  align-items: center;
}

/* ========================================
   Movie List
   ======================================== */
.movie-list-horizontal {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.movie-list-horizontal .movie-card {
  flex: 0 0 180px;
  scroll-snap-align: start;
}

.movie-list-vertical {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 20px;
  padding-bottom: 20px;
}

/* ========================================
   Movie Card
   ======================================== */
.movie-card {
  position: relative;
  border-radius: var(--border-radius);
  overflow: hidden;
  background: var(--bg-card);
  border: var(--card-border);
  transition: all 0.3s ease;
}

.movie-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}

.movie-card-link {
  display: block;
  color: inherit;
}

.movie-card-poster {
  position: relative;
  width: 100%;
  aspect-ratio: 2/3;
  overflow: hidden;
  background: var(--bg-input);
}

.movie-card-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.movie-card:hover .movie-card-poster img {
  transform: scale(1.05);
}

.movie-card-info {
  padding: 12px;
}

.movie-card-rating {
  font-size: 13px;
  font-weight: 600;
  color: var(--warning);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.movie-card-rating i {
  font-size: 12px;
}

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

.movie-card-year {
  font-size: 12px;
  color: var(--text-muted);
}

.movie-card-watchlist-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all var(--transition);
  opacity: 0;
  transform: scale(0.8);
  z-index: 2;
}

.movie-card:hover .movie-card-watchlist-btn {
  opacity: 1;
  transform: scale(1);
}

.movie-card-watchlist-btn.active {
  background: var(--accent);
  opacity: 1;
  transform: scale(1);
}

.movie-card-watchlist-btn:hover {
  transform: scale(1.1);
}

/* Always show button on watchlist page */
.movie-list-vertical .movie-card-watchlist-btn,
.watchlist-page .movie-card-watchlist-btn {
  opacity: 1;
  transform: scale(1);
}

/* ========================================
   Rating Colors
   ======================================== */
.rating-high { color: var(--success) !important; }
.rating-mid { color: var(--warning) !important; }
.rating-low { color: var(--danger) !important; }

/* ========================================
   Infinite Scroll
   ======================================== */
.infinite-scroll {
  min-height: 200px;
}

.loading-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 30px;
  color: var(--text-muted);
  font-size: 14px;
}

.loading-indicator .spinner {
  width: 24px;
  height: 24px;
  margin: 0;
  border-width: 2px;
}

.scroll-sentinel {
  height: 1px;
}

/* ========================================
   Detail Page
   ======================================== */
.detail-page {
  padding-top: 0 !important;
}

.detail-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 50vh;
}

.detail-backdrop {
  position: relative;
  height: 50vh;
  min-height: 400px;
  overflow: hidden;
}

.detail-backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-backdrop-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.1) 0%,
    rgba(0, 0, 0, 0.6) 60%,
    var(--bg-primary) 100%
  );
}

.detail-content {
  display: flex;
  gap: 32px;
  margin-top: -120px;
  position: relative;
  z-index: 10;
  padding-bottom: 40px;
}

.detail-poster {
  flex-shrink: 0;
  width: 280px;
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: var(--card-border);
  aspect-ratio: 2/3;
}

.detail-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-info {
  flex: 1;
  padding-top: 20px;
}

.detail-title {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 8px;
}

.detail-tagline {
  font-size: 16px;
  font-style: italic;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

.detail-meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.detail-meta-item i {
  color: var(--accent);
  font-size: 13px;
}

.detail-rating {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  margin-bottom: 20px;
}

.rating-value {
  font-weight: 700;
  font-size: 24px;
}

.rating-count {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
}

.detail-overview {
  margin-bottom: 20px;
}

.detail-overview h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.detail-overview p {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-secondary);
}

.detail-director {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 15px;
}

.detail-director-label {
  color: var(--text-muted);
}

.detail-director-name {
  color: var(--text-primary);
  font-weight: 600;
}

.detail-director-name:hover {
  color: var(--accent);
}

.detail-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* Cast Grid */
.detail-cast {
  margin-top: 10px;
  padding-bottom: 40px;
}

.detail-cast .section-title {
  margin-bottom: 16px;
}

.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
}

.cast-card {
  text-align: center;
}

.cast-avatar {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 8px;
  background: var(--bg-input);
}

.cast-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cast-avatar-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 24px;
}

.cast-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cast-character {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========================================
   Search Page
   ======================================== */
.search-header {
  margin-bottom: 24px;
}

.search-input-wrapper {
  position: relative;
  margin-top: 16px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 16px;
}

.search-input {
  width: 100%;
  padding: 14px 48px 14px 48px;
  background: var(--bg-input);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

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

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input-wrapper .btn-icon {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.search-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.search-empty i {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.search-empty p {
  font-size: 16px;
}

/* ========================================
   Settings Page
   ======================================== */
.settings-page {
  max-width: 700px;
  margin: 0 auto;
}

.settings-card {
  background: var(--bg-card);
  border: var(--card-border);
  border-radius: var(--border-radius-lg);
  padding: 28px;
  margin-bottom: 20px;
}

.settings-card-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.settings-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.settings-description a {
  color: var(--accent);
  font-weight: 500;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
  outline: none;
  transition: border-color var(--transition);
}

.form-input:focus {
  border-color: var(--accent);
}

.form-status {
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

.form-status.error { color: var(--danger); }
.form-status.success { color: var(--success); }
.form-status.loading { color: var(--text-muted); }

.form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ========================================
   Watchlist Page
   ======================================== */
.watchlist-actions {
  display: flex;
  justify-content: center;
  padding: 30px 0;
}

/* ========================================
   Empty State
   ======================================== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
}

.empty-state i {
  font-size: 64px;
  color: var(--text-muted);
  opacity: 0.3;
  margin-bottom: 20px;
}

.empty-state h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ========================================
   Error Page
   ======================================== */
.error-page {
  text-align: center;
  padding: 80px 20px;
}

.error-page i {
  font-size: 48px;
  color: var(--danger);
  margin-bottom: 16px;
}

.error-page h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 10px;
}

.error-page p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* ========================================
   Modal (Trailer)
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}

.modal-closing {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeOut {
  to { opacity: 0; }
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  max-width: 900px;
  width: 100%;
}

.trailer-modal-content {
  background: #000;
}

.modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  opacity: 0.8;
  transition: opacity var(--transition);
  z-index: 10;
}

.modal-close:hover {
  opacity: 1;
}

.trailer-wrapper {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 */
}

.trailer-wrapper iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 768px) {
  .navbar-links {
    display: none;
  }

  .mobile-only {
    display: flex;
  }

  .detail-content {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 20px;
  }

  .detail-poster {
    width: 200px;
    margin-top: -80px;
  }

  .detail-info {
    padding-top: 0;
  }

  .detail-title {
    font-size: 24px;
  }

  .detail-meta {
    justify-content: center;
  }

  .detail-rating {
    justify-content: center;
  }

  .detail-actions {
    justify-content: center;
  }

  .detail-director {
    justify-content: center;
  }

  .detail-backdrop {
    height: 35vh;
    min-height: 280px;
  }

  .movie-list-vertical {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  .movie-list-horizontal .movie-card {
    flex: 0 0 150px;
  }

  .page-title {
    font-size: 22px;
  }

  .cast-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 12px;
  }

  .settings-card {
    padding: 20px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 16px;
  }

  .page {
    padding: 24px 0;
  }

  .movie-list-vertical {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
  }

  .movie-card-info {
    padding: 8px;
  }

  .movie-card-title {
    font-size: 13px;
  }

  .detail-poster {
    width: 180px;
  }

  .cast-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
}
