:root {
  --bg:      #0d0d0d;
  --surface: #1a1a2e;
  --card:    #16213e;
  --pink:    #e91e8c;
  --rose:    #ff6eb4;
  --yellow:  #ffd60a;
  --text:    #f0f0f0;
  --muted:   #9a9ab0;
  --border:  rgba(233, 30, 140, 0.2);
  --glow:    rgba(233, 30, 140, 0.25);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 4rem;
}

/* HEADER */
header {
  text-align: center;
  padding: 3.5rem 1rem 2rem;
  background: linear-gradient(180deg, #1a1a2e 0%, transparent 100%);
}
header h1 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 800;
  background: linear-gradient(90deg, var(--pink), var(--rose), var(--yellow));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: .5rem;
}
header p { color: var(--muted); font-size: 1rem; }

/* MAIN */
main { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }

/* BUSCA */
.search-box {
  display: flex;
  gap: .8rem;
  max-width: 560px;
  margin: 0 auto 2.5rem;
}
.search-box input {
  flex: 1;
  padding: .85rem 1.2rem;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-box input::placeholder { color: var(--muted); }
.search-box input:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--glow);
}
.search-box button {
  padding: .85rem 1.8rem;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--pink), var(--rose));
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  white-space: nowrap;
}
.search-box button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--glow);
}

/* UTILITÁRIOS */
.hidden { display: none !important; }
.error { text-align: center; color: var(--rose); font-size: 1rem; margin-bottom: 2rem; }
.loading {
  text-align: center; color: var(--muted); font-size: 1rem; margin-bottom: 2rem;
  animation: pulse .8s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: .4; } to { opacity: 1; } }

/* GÊNEROS */
.genre-filters {
  display: flex; flex-wrap: wrap; gap: .6rem;
  justify-content: center; margin-bottom: 1.5rem;
}
.genre-btn {
  padding: .45rem 1rem; border-radius: 100px;
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: .82rem; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.genre-btn:hover { border-color: var(--pink); color: var(--text); }
.genre-btn.active { background: var(--pink); border-color: var(--pink); color: #fff; }

/* ABAS */
.tabs { display: flex; gap: .6rem; justify-content: center; margin-bottom: 1.5rem; }
.tab {
  padding: .55rem 1.4rem; border-radius: 12px;
  border: 1.5px solid var(--border); background: transparent;
  color: var(--muted); font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.tab:hover { color: var(--text); border-color: var(--pink); }
.tab.active {
  background: linear-gradient(135deg, var(--pink), var(--rose));
  border-color: transparent; color: #fff;
}

/* TÍTULO DA SEÇÃO */
.section-title {
  color: var(--muted); text-align: center; margin-bottom: 1.5rem;
  letter-spacing: .05em; text-transform: uppercase; font-size: .78rem; font-weight: 700;
}

/* GRID */
#moviesGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.5rem;
}

/* CARD */
.movie-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; overflow: hidden; cursor: pointer;
  transition: transform .3s, box-shadow .3s;
  animation: fadeIn .4s ease both;
  position: relative;
}
.movie-card:hover { transform: translateY(-8px); box-shadow: 0 20px 40px var(--glow); }
.movie-card img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; }
.no-poster {
  width: 100%; aspect-ratio: 2/3; background: var(--surface);
  display: flex; align-items: center; justify-content: center; font-size: 3rem;
}
.movie-info { padding: 1rem; }
.movie-title {
  font-size: .92rem; font-weight: 700; margin-bottom: .4rem; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  color: var(--text);
}
.movie-meta { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; }
.movie-year { font-size: .8rem; color: var(--muted); }
.movie-rating { font-size: .8rem; font-weight: 700; color: var(--yellow); }

/* BOTÃO FAVORITO NO CARD */
.btn-fav {
  position: absolute; top: .6rem; right: .6rem;
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .2s, background .2s; z-index: 2;
}
.btn-fav:hover { transform: scale(1.2); }
.btn-fav.favoritado { background: var(--pink); }

/* FAVORITOS VAZIO */
.empty-favs {
  text-align: center; color: var(--muted);
  padding: 3rem 1rem; font-size: 1rem; grid-column: 1 / -1;
}

/* ================================
   MODAL
   O problema anterior: img com src=""
   ocupava espaço. Agora começa oculta.
================================ */
.modal {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.8); backdrop-filter: blur(4px);
}
.modal-box {
  position: relative; background: var(--card);
  border: 1px solid var(--border); border-radius: 20px;
  width: min(680px, 100%); max-height: 88vh;
  overflow-y: auto; z-index: 1; animation: fadeIn .3s ease;
}
.modal-close {
  position: absolute; top: .8rem; right: .8rem;
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.12); color: #fff; font-size: 1rem;
  cursor: pointer; z-index: 10; transition: background .2s;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--pink); }

/* Layout do conteúdo do modal — coluna no mobile, linha no desktop */
.modal-content {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  padding: 2rem;
}

/* Poster começa oculto — JS mostra quando há imagem */
#modalPoster {
  display: none;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 10px;
}

/* Info do modal */
.modal-info {
  display: flex;
  flex-direction: column;
  gap: .8rem;
}
.modal-info h2 {
  font-size: 1.35rem; font-weight: 800; line-height: 1.25;
  color: #fff;
}
.modal-meta { display: flex; gap: 1rem; font-size: .85rem; }
.modal-meta span { color: var(--muted); }
.modal-meta span:last-child { color: var(--yellow); font-weight: 700; }
#modalOverview {
  font-size: .9rem; line-height: 1.8; color: rgba(255,255,255,.7);
}
.btn-fav-modal {
  align-self: flex-start;
  padding: .7rem 1.4rem; border-radius: 12px; border: none;
  background: linear-gradient(135deg, var(--pink), var(--rose));
  color: #fff; font-weight: 700; font-size: .9rem;
  cursor: pointer; transition: transform .2s, box-shadow .2s;
}
.btn-fav-modal:hover { transform: translateY(-2px); box-shadow: 0 8px 20px var(--glow); }
.btn-fav-modal.favoritado { background: #333; color: var(--muted); }

/* Desktop: poster ao lado */
@media (min-width: 580px) {
  .modal-content { flex-direction: row; align-items: flex-start; }
  #modalPoster { width: 160px; min-width: 160px; max-height: none; }
}

/* ANIMAÇÕES */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px) {
  #moviesGrid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
}