/* =======================
   THEME VARIABLES
======================= */
:root {
  --bg: #111;
  --text: #fff;
  --card: #222;
  --accent: #e50914;
  --muted: #8b8b8b;
}

body.light {
  --bg: #fff;
  --text: #000;
  --card: #eee;
  --accent: #e50914;
  --muted: #666;
}

/* =======================
   GLOBAL
======================= */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
  text-align: center;
  overflow-x: hidden;
}

/* =======================
   HEADER
======================= */
header {
  padding: 15px 20px;
  background: var(--card);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  transition: background 0.3s, color 0.3s;
}

header h1 {
  margin: 0;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  height: 28px;
  width: auto;
  vertical-align: middle;
  margin-right: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Icon button (theme) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, background 0.3s, border-color 0.3s;
}
.icon-btn:hover { transform: translateY(-1px); border-color: var(--accent); }

/* Favorites / Watched open buttons */
#favorites-btn, #watched-btn {
  font-size: 1rem;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.3s, transform 0.1s;
}
#favorites-btn:hover, #watched-btn:hover { background: #c40812; transform: translateY(-1px); }
/* =======================
   CONTROLS (Polished)
======================= */
.controls {
  margin: 20px auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  min-height: 80px;
  background: var(--card);
  border-radius: 0;              /* remove rounded corners */
  box-shadow: 0 3px 8px rgba(0,0,0,0.25);
  width: 100%;                   /* span entire screen */
  max-width: none;               /* no limit */
}

/* All inputs, selects, and buttons unified */
.controls input,
.controls select,
.controls button {
  height: 36px;               /* same height */
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  flex: 0 0 auto;             /* don’t stretch */
  transition: border 0.2s, background 0.3s;
}

.controls input:focus,
.controls select:focus {
  border-color: var(--accent);
  outline: none;
}

/* Search button highlight */
.controls button {
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  border: none;
  cursor: pointer;
}
.controls button:hover {
  background: #c40812;
  transform: translateY(-1px);
}/* =======================
   LANGUAGE DROPDOWN SEARCH
======================= */
/* Language filter: keep inline */
.language-dropdown {
  display: flex;
  flex-direction: row;   /* INLINE not stacked */
  align-items: center;
  gap: 6px;
}
#language-search {
  flex: 1;
  min-width: 120px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: var(--bg);
  color: var(--text);
}
#language-filter {
  min-width: 130px;
  height: 36px;
}
/* =======================
   MOVIES GRID
======================= */
#movies {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 15px;
  margin: 20px;
}

/* Movie card */
.movie {
  background: var(--card);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.3s, background 0.3s;
  position: relative;
  overflow: hidden;
}

.movie:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

.movie img {
  width: 100%;
  height: 240px;
  border-radius: 8px;
  object-fit: cover;
  transition: transform 0.3s;
}

.movie:hover img { transform: scale(1.04); }

.movie h3 {
  font-size: 0.95rem;
  margin: 8px 0 0;
}

.movie span {
  font-size: 0.75rem;
  opacity: 0.8;
}

.movie .rating-inline {
  color: gold;
  font-size: 0.82rem;
  margin-top: 4px;
}

/* Corner buttons */
.movie > .fav-btn, .movie > .watched-btn {
  position: absolute;
  top: 14px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: #00000050;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.1s, background 0.3s;
}
.movie > .fav-btn { right: 14px; }
.movie > .watched-btn { right: 60px; }
.movie > .fav-btn:hover, .movie > .watched-btn:hover { transform: translateY(-1px); background: #00000070; }
/* Movie details modal layout */
.modal-movie {
  display: flex;
  gap: 20px;
  padding: 20px;
  align-items: flex-start;
}

.modal-movie img {
  width: 220px;
  height: auto;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.modal-info {
  flex: 1;
  text-align: left;
  overflow-y: auto;
  max-height: 70vh;
}

.modal-info h2 {
  margin-top: 0;
  margin-bottom: 10px;
}

.modal-info p {
  margin: 6px 0;
  line-height: 1.4;
}

.modal-links {
  margin-top: 15px;
  display: flex;
  gap: 10px;
}

.modal-links a {
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.3s;
}

.modal-links a:hover {
  background: #c40812;
}
/* Close button for details modal */
#closeModal {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 28px;
  font-weight: bold;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s, color 0.2s;
  z-index: 10;
}

#closeModal:hover {
  transform: scale(1.15);
  color: var(--accent);
}

/* =======================
   PAGINATION
======================= */
.pagination {
  margin: 20px;
  display: flex;
  justify-content: center;
  gap: 12px;
  align-items: center;
}

.pagination button {
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.3s, color 0.3s, transform 0.1s;
  background: var(--card);
  color: var(--text);
}
.pagination button:hover { background: var(--accent); color: #fff; transform: translateY(-1px); }

/* =======================
   LOADING
======================= */
.loading {
  display: flex;
  justify-content: center;
  margin: 20px;
}
.loading.hidden { display: none; }

.spinner {
  border: 4px solid #ccc;
  border-top: 4px solid var(--accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* =======================
   MODALS
======================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  justify-content: center;
  align-items: center;
  padding: 20px;
  z-index: 1000;
  transition: opacity 0.3s;
}

.modal.open {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  max-width: 900px;
  width: 95%;
  max-height: 90vh;
  display: flex;
  flex-direction: column; /* vertical layout for favorite/watched */
  overflow: hidden;
  position: relative;
  box-shadow: 0 8px 30px rgba(0,0,0,0.7);
  transition: background 0.3s, color 0.3s;
}

/* Header row inside modal */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 8px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-header-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Close button inside modal-header */
.modal-header .close {
  font-size: 24px;
  font-weight: bold;
  color: #fff;
  cursor: pointer;
  padding: 6px 12px;  /* larger clickable area */
  transition: transform 0.1s, color 0.2s;
  position: relative;
  z-index: 101;
}
.modal-header .close:hover {
  transform: scale(1.1);
  color: var(--accent);
}

/* Clear All button in header */
.ghost-btn {
  padding: 6px 14px;  /* larger clickable area */
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.3s, transform 0.1s;
  position: relative;
  z-index: 101;
}
.ghost-btn:hover {
  background: #ff6b6b;
  transform: translateY(-1px);
}

/* Scrollable list inside modal */
#favorites-list, #watched-list {
  padding: 15px;
  overflow-y: auto;
  flex: 1;
  max-height: calc(90vh - 60px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px; /* prevents overlay under buttons */
}

/* Each item */
.fav-item, .watched-item {
  display: flex;
  align-items: center;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.fav-item:hover { background: rgba(255,0,0,0.18); }
.watched-item:hover { background: rgba(255,255,0,0.18); }

.fav-item img, .watched-item img {
  width: 50px;
  height: 75px;
  border-radius: 4px;
  margin-right: 10px;
  object-fit: cover;
}

.fav-item span, .watched-item span {
  flex: 1;
  text-align: left;
  font-size: 0.95rem;
}

/* Empty state styling */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 40px auto;
  opacity: 0.9;
  gap: 10px;
}

.empty img { width: 110px; height: 110px; object-fit: contain; opacity: 0.9; }
.empty p { margin: 0; color: var(--muted); font-size: 1rem; }

/* Scrollbar for modal list */
#favorites-list::-webkit-scrollbar,
#watched-list::-webkit-scrollbar {
  width: 6px;
}

#favorites-list::-webkit-scrollbar-thumb,
#watched-list::-webkit-scrollbar-thumb {
  background-color: var(--accent);
  border-radius: 3px;
}

#favorites-list::-webkit-scrollbar-track,
#watched-list::-webkit-scrollbar-track {
  background: var(--card);
}

/* =======================
   RESPONSIVE
======================= */
@media (max-width: 768px) {
  header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .controls { flex-direction: column; align-items: stretch; }
  #movies { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .movie img { height: 210px; }
  .modal-content { width: 95%; }
  .modal-header h2 { font-size: 1rem; }
  .ghost-btn { padding: 4px 10px; font-size: 0.85rem; }
  .modal-header .close { font-size: 22px; }
}

@media (max-width: 500px) {
  .modal-header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .modal-header-buttons { width: 100%; justify-content: flex-end; }
}
