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

[hidden] {
  display: none !important;
}

:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface-hover: #1a1a24;
  --border: #1e1e2a;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-glow: rgba(139, 92, 246, 0.15);
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

html {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

/* ── Hero / Search Header ───────────────────────── */

.hero {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  padding: 28px 24px 20px;
}

.hero-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.tagline {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.search-wrapper {
  position: relative;
  width: 100%;
  max-width: 640px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 14px 52px 14px 48px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-shortcut {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 8px;
  font-size: 0.75rem;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  pointer-events: none;
}

.filters {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 640px;
}

.filters select {
  flex: 1;
  padding: 10px 14px;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  transition: border-color 0.2s;
}

.filters select:focus {
  border-color: var(--accent);
}

/* ── Main Content ────────────────────────────────── */

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.results-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  min-height: 20px;
}

/* ── Movie Grid ──────────────────────────────────── */

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s;
}

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

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

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

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

.card-poster .no-poster {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.card-rating {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  color: #facc15;
  display: flex;
  align-items: center;
  gap: 3px;
}

.card-info {
  padding: 12px;
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-title mark {
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 2px;
}

.card-year {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.card-overview {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Hover Tooltip ──────────────────────────────── */

.card-tooltip {
  position: fixed;
  z-index: 80;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: tooltipIn 0.15s ease;
}

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

.tooltip-title {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.tooltip-meta {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.tooltip-meta .rating {
  color: #facc15;
  font-weight: 600;
}

.tooltip-overview {
  margin-top: 12px;
  font-size: 0.8125rem;
  line-height: 1.7;
  color: var(--text-muted);
}

.tooltip-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

/* ── Pagination ─────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 32px;
  flex-wrap: wrap;
}

.page-btn {
  padding: 8px 14px;
  font-size: 0.875rem;
  font-family: inherit;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.page-btn:hover:not(:disabled):not(.active) {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.page-ellipsis {
  padding: 8px 4px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Loading ─────────────────────────────────────── */

.loading {
  display: flex;
  justify-content: center;
  padding: 60px 0;
}

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

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

/* ── Empty State ─────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text);
}

.empty-state span {
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ── Modal ───────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
}

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

.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 10;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

.modal-backdrop {
  width: 100%;
  aspect-ratio: 16 / 7;
  object-fit: cover;
  display: block;
}

.modal-content {
  padding: 24px;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.modal-meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.modal-meta .rating {
  color: #facc15;
  font-weight: 600;
}

.modal-overview {
  margin-top: 16px;
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--text-muted);
}

.modal-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.genre-tag {
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--accent-glow);
  color: var(--accent);
  border-radius: 999px;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

/* ── Chat Panel ─────────────────────────────────── */

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  z-index: 60;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.chat-panel.open {
  transform: translateX(0);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--accent);
}

.chat-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.2s;
}

.chat-toggle:hover {
  color: var(--text);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.8125rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.chat-bubble.ai {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border: none;
}

.chat-bubble.thinking {
  padding: 14px 20px;
}

.dot-pulse {
  display: inline-flex;
  gap: 4px;
}

.dot-pulse::before,
.dot-pulse::after,
.dot-pulse {
  position: relative;
}

.dot-pulse::before { content: ""; }
.dot-pulse::after { content: ""; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

.dot-pulse,
.dot-pulse::before,
.dot-pulse::after {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  display: inline-block;
  animation: dotPulse 1.4s infinite ease-in-out;
}

.dot-pulse::before {
  position: absolute;
  left: -10px;
  animation-delay: -0.32s;
}

.dot-pulse::after {
  position: absolute;
  left: 10px;
  animation-delay: 0.16s;
}

.chat-movies {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 90%;
  align-self: flex-start;
}

.chat-movie-card {
  display: flex;
  gap: 10px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.chat-movie-card:hover {
  border-color: var(--accent);
}

.chat-movie-card img {
  width: 44px;
  height: 66px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.no-poster-sm {
  width: 44px;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 6px;
  flex-shrink: 0;
}

.chat-movie-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.chat-movie-title {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-movie-meta {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.chat-input-form {
  display: flex;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input-form input {
  flex: 1;
  padding: 10px 14px;
  font-size: 0.8125rem;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

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

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

.chat-input-form button {
  padding: 10px 12px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chat-input-form button:hover {
  background: var(--accent-hover);
}

/* Floating action button */

.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 55;
  width: 56px;
  height: 56px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
  transition: transform 0.2s, background 0.2s;
}

.chat-fab:hover {
  transform: scale(1.08);
  background: var(--accent-hover);
}

.chat-fab.hidden {
  display: none;
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 640px) {
  .hero {
    padding: 20px 16px 16px;
  }

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

  .logo {
    font-size: 1.25rem;
  }

  .modal {
    max-height: 92vh;
  }

  .chat-panel {
    width: 100%;
  }
}
