/* =============================================
   FediFlix Popup System
   Responsive: popover on desktop, modal on mobile
   ============================================= */

/* Backdrop */
.ff-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0);
  transition: background 0.25s ease, backdrop-filter 0.25s ease;
}
.ff-popup-backdrop.active {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

/* Popup container — desktop: anchored popover */
.ff-popup {
  position: absolute;
  z-index: 1000;
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}
.ff-popup.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* Popup content card — shared base */
.ff-popup-content {
  position: relative;
  background: var(--ff-card-bg, #1a1a2e);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  min-width: 320px;
  max-width: 420px;
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.3),
    0 16px 48px rgba(0, 0, 0, 0.4);
}

/* ── Nuclear Pico CSS reset inside popups ──
   Pico styles bare elements (label, select, textarea, button, input)
   with padding/width/display that bloats popup forms.
   `all: unset` strips everything, then we rebuild from scratch. ── */
.ff-popup-content label,
.ff-popup-content select,
.ff-popup-content textarea,
.ff-popup-content > button,
.ff-popup-content input {
  all: unset;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ff-text-primary, #e2e8f0);
}

/* Review popup — full modal, viewport-relative sizing */
.ff-popup:has(.ff-popup-review) {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) scale(0.97) !important;
  width: min(90vw, 640px);
}
.ff-popup.active:has(.ff-popup-review) {
  transform: translate(-50%, -50%) scale(1) !important;
}
.ff-popup-review {
  min-width: unset;
  max-width: unset;
  width: 100%;
  padding: 2rem 2.25rem;
  display: flex;
  flex-direction: column;
}
.ff-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.ff-popup-review .ff-popup-title {
  font-size: 1.35rem;
  margin-bottom: 0;
  flex: 1;
}
.ff-popup-review .ff-popup-lang {
  margin-top: 0;
  flex-shrink: 0;
}
.ff-popup-review .ff-popup-select {
  padding: 0.4rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ff-text-primary, #e2e8f0);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.ff-popup-review .ff-popup-select:hover,
.ff-popup-review .ff-popup-select:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
  outline: none;
}
.ff-popup-review .ff-popup-stars--small {
  margin-bottom: 1rem;
}
.ff-popup-review .ff-popup-stars--small .ff-popup-star svg {
  width: 30px;
  height: 30px;
}
.ff-popup-review .ff-popup-textarea {
  min-height: min(35vh, 280px);
  max-height: 50vh;
  font-size: 0.95rem;
  padding: 1rem 1.1rem;
  border-radius: 10px;
}
.ff-popup-review .ff-popup-actions {
  margin-top: 1.25rem;
  justify-content: space-between;
  align-items: center;
}
.ff-popup-review .ff-popup-submit {
  padding: 0.6rem 2rem;
  font-size: 0.95rem;
}

/* Wider content card for watchlist popup */
.ff-popup-watchlist {
  min-width: 340px;
  max-width: 440px;
}

.ff-popup-title {
  margin: 0 0 1rem;
  padding-right: 1.5rem; /* room for close button */
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--ff-font-heading, 'Outfit', sans-serif);
  letter-spacing: -0.02em;
  color: var(--ff-text-primary, #e2e8f0);
}

.ff-popup-desc {
  margin: -0.25rem 0 0.75rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ff-text-muted, #94a3b8);
}

/* Close button — top-right corner */
.ff-popup-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--ff-text-muted, #64748b);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  line-height: 0;
}
.ff-popup-close:hover {
  color: var(--ff-text-primary, #e2e8f0);
  background: rgba(255, 255, 255, 0.08);
}

/* =============================================
   Star Rating (Rate & Review popups)
   ============================================= */

.ff-popup-stars {
  display: flex;
  gap: 6px;
  margin-bottom: 1rem;
  justify-content: center;
}

.ff-popup-stars--small {
  justify-content: flex-start;
  margin-bottom: 0.75rem;
}
.ff-popup-stars--small .ff-popup-star svg {
  width: 26px;
  height: 26px;
}

.ff-popup-star {
  background: none;
  border: none;
  padding: 3px;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.22, 1, 0.36, 1);
  color: rgba(255, 255, 255, 0.15);
}
.ff-popup-star svg {
  width: 36px;
  height: 36px;
  fill: currentColor;
  stroke: none;
  transition: color 0.15s ease;
}
.ff-popup-star:hover {
  transform: scale(1.2);
}
.ff-popup-star.highlighted svg,
.ff-popup-star.selected svg {
  color: #fbbf24;
  filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.3));
}

/* Star label text (e.g., "Good") shown below stars */
.ff-popup-star-label {
  text-align: center;
  font-size: 0.75rem;
  color: var(--ff-text-muted, #94a3b8);
  margin-top: -0.35rem;
  margin-bottom: 0.5rem;
  min-height: 1em;
}

/* =============================================
   Textarea (Review popup)
   ============================================= */

.ff-popup-textarea {
  display: block;
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--ff-text-primary, #e2e8f0);
  resize: vertical;
  min-height: 100px;
  max-height: 200px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.ff-popup-textarea:focus {
  outline: none;
  border-color: var(--ff-accent-movie, #8b5cf6);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15);
}
.ff-popup-textarea::placeholder {
  color: var(--ff-text-muted, #64748b);
}

/* =============================================
   Spoiler checkbox (Review popup)
   ============================================= */

.ff-popup-spoiler {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--ff-text-muted, #94a3b8);
  cursor: pointer;
  user-select: none;
}
.ff-popup-spoiler input {
  display: none;
}
.ff-popup-spoiler .ff-toggle-track {
  display: inline-block;
  width: 32px;
  height: 18px;
  min-width: 32px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
}
.ff-popup-spoiler .ff-toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: #94a3b8;
  border-radius: 50%;
  transition: transform 0.2s ease, background 0.2s ease;
}
.ff-popup-spoiler input:checked + .ff-toggle-track {
  background: var(--ff-accent-movie, #8b5cf6);
}
.ff-popup-spoiler input:checked + .ff-toggle-track::after {
  transform: translateX(14px);
  background: #fff;
}
.ff-popup-spoiler:hover {
  color: var(--ff-text, #e2e8f0);
}

/* =============================================
   Language selector (Review popup)
   ============================================= */

.ff-popup-lang {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.ff-popup-lang label {
  display: inline;
  font-size: 0.85rem;
  color: var(--ff-text-muted, #94a3b8);
  white-space: nowrap;
  flex-shrink: 0;
}

.ff-popup-select {
  display: block;
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.45rem 2rem 0.45rem 0.7rem;
  font-size: 0.85rem;
  color: var(--ff-text-primary, #e2e8f0);
  cursor: pointer;
  transition: border-color 0.2s ease;
  /* Custom dropdown arrow */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
}

.ff-popup-select:focus {
  outline: none;
  border-color: var(--ff-accent-movie, #8b5cf6);
}

.ff-popup-select option {
  background: var(--ff-card-bg, #1a1a2e);
  color: var(--ff-text-primary, #e2e8f0);
}

/* =============================================
   Actions row
   ============================================= */

.ff-popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.ff-popup-submit {
  display: inline-block;
  background: var(--ff-accent-movie, #8b5cf6);
  color: #fff;
  border-radius: 8px;
  padding: 0.55rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.ff-popup-submit:hover:not([disabled]) {
  background: #7c3aed;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}
.ff-popup-submit:active:not([disabled]) {
  transform: translateY(0);
}
.ff-popup-submit[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

/* =============================================
   Watchlist picker
   ============================================= */

.ff-popup-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding: 0.25rem;
}

/* Custom scrollbar for watchlist */
.ff-popup-list::-webkit-scrollbar {
  width: 4px;
}
.ff-popup-list::-webkit-scrollbar-track {
  background: transparent;
}
.ff-popup-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.ff-popup-loading {
  text-align: center;
  color: var(--ff-text-muted, #94a3b8);
  font-size: 0.85rem;
  padding: 1.5rem 0;
}
.ff-popup-empty {
  text-align: center;
  color: var(--ff-text-muted, #64748b);
  font-size: 0.85rem;
  padding: 1rem 0;
  margin: 0;
}

/* Watchlist item — card style */
.ff-popup-wl-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  color: var(--ff-text-primary, #e2e8f0);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s;
}
.ff-popup-wl-item:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.12);
}

/* In-list state — purple tint */
.ff-popup-wl-item--in {
  background: rgba(168, 85, 247, 0.1);
  border-color: rgba(168, 85, 247, 0.2);
}
.ff-popup-wl-item--in:hover {
  background: rgba(168, 85, 247, 0.18);
  border-color: rgba(168, 85, 247, 0.3);
}
.ff-popup-wl-item--busy {
  opacity: 0.5;
  pointer-events: none;
}

/* Name with optional check icon */
.ff-popup-wl-name {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}
.ff-popup-wl-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ff-popup-wl-item--in .ff-popup-wl-name > svg {
  color: #a855f7;
  flex-shrink: 0;
}

/* Action icon (add/remove) — sits after name */
.ff-popup-wl-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.ff-popup-wl-action--add {
  color: #22c55e;
}
.ff-popup-wl-item:hover .ff-popup-wl-action--add {
  background: rgba(34, 197, 94, 0.2);
}
.ff-popup-wl-action--remove {
  color: #ef4444;
}
.ff-popup-wl-item:hover .ff-popup-wl-action--remove {
  background: rgba(239, 68, 68, 0.2);
}

.ff-popup-wl-item svg {
  flex-shrink: 0;
}

/* Separator between list and create */
.ff-popup-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0.25rem 0 0.75rem;
  border: none;
}

.ff-popup-create {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.ff-popup-input {
  display: block;
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--ff-text-primary, #e2e8f0);
  transition: border-color 0.2s ease;
}
.ff-popup-input:focus {
  outline: none;
  border-color: var(--ff-accent-movie, #8b5cf6);
}
.ff-popup-input::placeholder {
  color: var(--ff-text-muted, #64748b);
}
.ff-popup-create-btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-block;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ff-text-primary, #e2e8f0);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  margin: 0;
  box-shadow: none;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.ff-popup-create-btn:hover:not([disabled]) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}
.ff-popup-create-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

/* =============================================
   Follow toggle
   ============================================= */

.ff-popup-follow-btn {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  box-shadow: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0.7rem 1.25rem;
  color: var(--ff-text-primary, #e2e8f0);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.ff-popup-follow-btn:hover:not([disabled]) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}
.ff-popup-follow-btn.following {
  background: var(--ff-accent-tv, #06b6d4);
  border-color: var(--ff-accent-tv, #06b6d4);
  color: #fff;
}

/* =============================================
   Feedback message
   ============================================= */

.ff-popup-feedback {
  min-height: 1.2em;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  text-align: center;
  color: var(--ff-text-muted, #94a3b8);
  transition: color 0.2s;
}
.ff-popup-feedback:empty {
  margin-top: 0;
  min-height: 0;
}
.ff-popup-feedback.success {
  color: #22c55e;
}
.ff-popup-feedback.error {
  color: #ef4444;
}

/* =============================================
   Poster Card Quick-Action Buttons
   ============================================= */

.poster-card__actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.poster-card__action-btn {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.15s;
}
.poster-card__action-btn:hover {
  background: var(--ff-accent-movie, #8b5cf6);
  border-color: var(--ff-accent-movie, #8b5cf6);
  color: #fff;
  transform: scale(1.1);
}
.poster-card__action-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* Mobile: always show overlay (no hover) */
@media (hover: none) {
  .poster-card__overlay {
    opacity: 1 !important;
  }
}

/* =============================================
   Mobile: Convert popups to centered modals
   ============================================= */

@media (max-width: 640px) {
  /* Small popups (rate, watchlist, follow) → centered modal */
  .ff-popup {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(0.95) !important;
    width: calc(100vw - 2rem);
    max-width: 400px;
  }
  .ff-popup.active {
    transform: translate(-50%, -50%) scale(1) !important;
  }

  .ff-popup-content {
    min-width: unset;
    max-width: unset;
    width: 100%;
    padding: 1.25rem;
  }

  .ff-popup-watchlist {
    min-width: unset;
    max-width: unset;
  }

  .ff-popup-star svg {
    width: 32px;
    height: 32px;
  }

  .ff-popup-submit {
    display: block;
    width: 100%;
    padding: 0.5rem;
    text-align: center;
  }

  /* Review popup — near-fullscreen on mobile */
  .ff-popup:has(.ff-popup-review) {
    width: 100vw;
    height: 100dvh;
    max-width: unset;
    top: 0 !important;
    left: 0 !important;
    transform: translateY(100%) !important;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    border-radius: 0;
  }
  .ff-popup.active:has(.ff-popup-review) {
    transform: translateY(0) !important;
  }
  .ff-popup-review {
    height: 100%;
    border-radius: 0;
    padding: 1.5rem 1.25rem calc(env(safe-area-inset-bottom, 0px) + 1.25rem);
    display: flex;
    flex-direction: column;
  }
  .ff-popup-review .ff-popup-textarea {
    flex: 1;
    min-height: 120px;
    max-height: unset;
  }
  .ff-popup-review .ff-popup-submit {
    padding: 0.75rem;
    font-size: 1rem;
  }
}

/* =============================================
   Reduced motion
   ============================================= */

@media (prefers-reduced-motion: reduce) {
  .ff-popup,
  .ff-popup-backdrop,
  .ff-popup-star,
  .ff-popup-submit,
  .poster-card__action-btn {
    transition: none !important;
  }
}
