.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-detail);
  background: var(--bg-overlay);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}

.modal-backdrop.is-open {
  opacity: 1;
}

.modal-backdrop.is-closing {
  opacity: 0;
  pointer-events: none;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-backdrop-high {
  z-index: var(--z-modal-high);
}

.sheet {
  position: relative;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-modal);
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition: opacity 220ms var(--ease-out), transform 240ms var(--ease-spring-soft);
}

.modal-backdrop.is-open .sheet {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.modal-backdrop.is-closing .sheet {
  opacity: 0;
  transform: translateY(10px) scale(0.98);
}

.compact-sheet {
  max-width: 440px;
}

.account-sheet {
  max-width: 740px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-sheet {
  max-width: 880px;
  display: flex;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: rgba(8, 11, 16, 0.78);
  color: var(--text-primary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface-hover);
}

.modal-pad {
  padding: var(--sp-6);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-h2);
  font-weight: 700;
  margin-bottom: var(--sp-2);
  padding-right: 34px;
}

.modal-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--sp-5);
}

.text-link {
  color: var(--accent-secondary);
  text-decoration: none;
}

.text-link:hover,
.text-link:focus-visible {
  text-decoration: underline;
}

/* Detail Sheet */
.detail-poster {
  position: relative;
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-surface);
  overflow: hidden;
}

.detail-poster::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 58%, var(--bg-elevated) 100%);
}

.detail-poster img {
  width: 100%;
  height: 100%;
  min-height: 390px;
  object-fit: cover;
  display: block;
}

.detail-body {
  flex: 1;
  min-width: 0;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
}

.detail-eyebrow {
  margin-bottom: var(--sp-2);
}

.detail-title {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: var(--sp-3);
  padding-right: 36px;
}

.detail-facts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--sp-3);
}

.detail-genres {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}

.genre-chip {
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.detail-overview {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--sp-5);
}

.ep-select {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
  padding: var(--sp-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.ep-select[hidden] {
  display: none;
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-inline.grow {
  flex: 1;
  min-width: 180px;
}

.field-inline label {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.field-inline select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-elevated);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a8b4c4' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 8px 32px 8px 10px;
  font-size: var(--text-sm);
  cursor: pointer;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3);
  margin-top: auto;
}

.list-picker-wrap {
  position: relative;
}

.list-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  padding: var(--sp-2);
  z-index: 10;
  transform-origin: bottom left;
  animation: dropdownIn 160ms var(--ease-spring-soft);
}

.list-popover[hidden] {
  display: none;
}

.list-pop-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.list-pop-item:hover {
  background: var(--bg-surface-hover);
}

/* Forms & Auth */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
}

.form-field input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

.form-field input:focus {
  border-color: var(--border-focus);
  outline: none;
}

.form-field input[readonly] {
  opacity: 0.7;
  cursor: not-allowed;
}

.input-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-password-wrap input {
  padding-right: 76px;
}

.btn-toggle-vis {
  position: absolute;
  right: 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 6px 8px;
  cursor: pointer;
}

.btn-toggle-vis:hover {
  color: var(--text-primary);
}

.field-error {
  font-size: var(--text-xs);
  color: var(--status-danger);
}

.banner-alert {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  margin-bottom: var(--sp-4);
}

.banner-alert.error {
  background: var(--status-danger-bg);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--status-danger);
}

.banner-alert.success {
  background: var(--status-success-bg);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: var(--status-success);
}

.banner-alert.info {
  background: var(--status-info-bg);
  border: 1px solid rgba(96, 165, 250, 0.35);
  color: var(--status-info);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  margin: var(--sp-4) 0;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.btn-google {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.btn-google:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--border-strong);
}

.auth-row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--text-xs);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--brand-crimson);
}

.auth-footer-switch {
  margin-top: var(--sp-5);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* Password strength meter */
.pw-meter {
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--bg-surface-hover);
  overflow: hidden;
  margin-top: 4px;
}

.pw-meter-bar {
  height: 100%;
  width: 0%;
  transition: width var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}

.pw-meter-bar.weak { width: 33%; background: var(--status-danger); }
.pw-meter-bar.medium { width: 66%; background: var(--status-warning); }
.pw-meter-bar.strong { width: 100%; background: var(--status-success); }

.pw-checklist {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-muted);
}

.pw-checklist span.ok {
  color: var(--status-success);
}

/* Account Modal */
.account-layout {
  display: flex;
  flex: 1;
  min-height: 440px;
  max-height: 90vh;
  overflow: hidden;
}

.account-nav {
  width: 210px;
  flex-shrink: 0;
  padding: var(--sp-5) var(--sp-3);
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  overflow-y: auto;
  position: relative;
  z-index: 2;
}

.account-heading {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  padding: 0 var(--sp-3) var(--sp-3);
}

.acc-tab {
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px var(--sp-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
}

.acc-tab:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.acc-tab.on {
  background: var(--accent-primary-muted);
  color: var(--accent-primary);
  font-weight: 600;
}

.acc-tab.danger.on {
  background: var(--status-danger-bg);
  color: var(--status-danger);
}

.account-content {
  flex: 1;
  padding: var(--sp-6);
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  z-index: 1;
}

.acc-section-title {
  font-family: var(--font-display);
  font-size: var(--text-h3);
  margin-bottom: var(--sp-4);
}

.acc-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--sp-6) 0;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.session-info-title {
  font-size: var(--text-sm);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.session-info-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

.badge-current {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-primary-muted);
  color: var(--accent-primary);
}

.danger-zone {
  padding: var(--sp-5);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.05);
}

.modal-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

@media (max-width: 767px) {
  .detail-sheet {
    flex-direction: column;
  }
  .detail-poster {
    width: 100%;
    height: 220px;
  }
  .detail-poster::after {
    background: linear-gradient(180deg, transparent 42%, var(--bg-elevated) 100%);
  }
  .detail-poster img {
    min-height: 0;
    height: 220px;
  }
  .account-layout {
    flex-direction: column;
    min-height: 0;
    max-height: 90vh;
  }
  .account-nav {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    align-items: center;
    padding: 48px var(--sp-3) var(--sp-2);
    gap: var(--sp-1);
  }
  .account-nav::-webkit-scrollbar {
    display: none;
  }
  .acc-tab {
    white-space: nowrap;
    flex-shrink: 0;
  }
  .account-heading {
    position: absolute;
    top: 14px;
    left: 16px;
    right: 52px;
    padding: 0;
    display: block;
    font-size: var(--text-h3);
  }
}

@media (max-width: 1023px) {
  .list-popover {
    left: auto;
    right: 0;
    max-width: calc(100vw - 32px);
  }
}

@media (max-width: 639px) {
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .sheet {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 92dvh;
    transform: translateY(28px);
  }
  .modal-backdrop.is-open .sheet {
    transform: translateY(0);
  }
  .modal-backdrop.is-closing .sheet {
    transform: translateY(28px);
  }
  .compact-sheet {
    max-width: 100%;
  }
  .account-sheet,
  .account-layout {
    max-height: 92dvh;
  }
  .detail-body,
  .account-content,
  .modal-pad {
    padding: var(--sp-4);
  }
  .account-content {
    padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom, 0px));
  }
  .field-inline,
  .field-inline.grow {
    width: 100%;
    min-width: 0;
  }
  .detail-actions .btn {
    flex: 1 1 auto;
  }
  .list-picker-wrap {
    flex: 1 1 100%;
  }
  .list-picker-wrap .btn {
    width: 100%;
  }
  .list-popover {
    left: 0;
    right: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }
}
