/* =============================================================================
   Avatar Components — Campaign Creation Upload + In-Game Display
   ============================================================================= */

/* ---------- Upload Zone (Campaign Wizard Step) ---------- */

.avatar-upload-step {
  text-align: center;
  padding: 0.25rem 0;
}

.avatar-source-segment,
.portrait-source-segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0.25rem;
  border-radius: 12px;
  background: rgba(8, 6, 16, 0.65);
  border: 1px solid rgba(168, 85, 247, 0.35);
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.avatar-source-segment-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: none;
  background: transparent;
  color: rgba(220, 214, 255, 0.75);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.avatar-source-segment-btn.is-active {
  background: linear-gradient(
    135deg,
    rgba(168, 85, 247, 0.45),
    rgba(124, 58, 237, 0.35)
  );
  color: #fff;
  box-shadow: 0 0 0 1px rgba(196, 181, 253, 0.35);
}

.avatar-source-segment-icon {
  flex-shrink: 0;
  opacity: 0.95;
}

.avatar-source-segment-btn:focus-visible,
.portrait-source-segment .avatar-source-segment-btn:focus-visible {
  outline: 2px solid rgba(196, 181, 253, 0.95);
  outline-offset: 2px;
}

.avatar-source-segment.mode-ai
  .avatar-source-segment-btn[data-avatar-mode="ai"].is-active:focus-visible {
  outline: 2px solid rgba(196, 181, 253, 0.95);
  outline-offset: 2px;
}

.avatar-ai-step {
  max-width: 640px;
  margin: 0 auto;
  text-align: left;
}

/* In-game modal owns the active portrait panel; hide wizard duplicates. */
body.portrait-modal-active #avatar-ai-panel,
body.portrait-modal-active .campaign-wizard [data-portrait-panel-root] {
  display: none !important;
}

.portrait-ai-layout {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 1rem;
  align-items: start;
}

.portrait-ai-preview-ring {
  position: relative;
  width: min(210px, 42vw, 100%);
  height: min(210px, 42vw, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid rgba(168, 85, 247, 0.45);
  background: radial-gradient(circle at 30% 20%, rgba(168, 85, 247, 0.2), #120a22);
  box-shadow: 0 0 24px rgba(124, 58, 237, 0.25);
  overflow: hidden;
}

.portrait-ai-preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  color: rgba(196, 181, 253, 0.85);
  text-align: center;
  padding: 0.5rem;
}

.portrait-ai-preview-icon {
  font-size: 1.35rem;
}

.portrait-ai-preview-img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.45s ease;
}

.portrait-ai-preview-img.is-visible {
  opacity: 1;
}

.portrait-ai-gen-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(10, 6, 20, 0.72);
  color: #e9d5ff;
  font-size: 0.75rem;
  text-align: center;
  padding: 0.75rem;
  pointer-events: none;
}

.portrait-ai-preview-ring.is-generating .portrait-ai-gen-overlay {
  display: flex;
}

.portrait-ai-preview-ring.is-generating .portrait-ai-preview-img.is-visible {
  opacity: 0.2;
}

.portrait-ai-label {
  display: block;
  font-weight: 600;
  color: #f3efff;
  margin-bottom: 0.25rem;
}

.portrait-ai-helper {
  font-size: 0.82rem;
  color: rgba(184, 180, 207, 0.8);
  margin: 0 0 0.65rem;
  line-height: 1.4;
}

.portrait-ai-textarea-wrap {
  position: relative;
  border-radius: 12px;
}

.portrait-ai-textarea {
  width: 100%;
  min-height: 7.5rem;
  resize: vertical;
  box-sizing: border-box;
  background: rgba(8, 6, 16, 0.85);
  color: #f8f5ff;
  border: 1px solid rgba(168, 85, 247, 0.35);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  font-size: 0.92rem;
  line-height: 1.45;
}

.portrait-ai-textarea:focus {
  outline: none;
  border-color: rgba(196, 181, 253, 0.75);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2);
}

.portrait-ai-shimmer {
  pointer-events: none;
  position: absolute;
  inset: 0;
  border-radius: 12px;
  opacity: 0;
  background: linear-gradient(
    110deg,
    transparent 25%,
    rgba(168, 85, 247, 0.12) 45%,
    rgba(196, 181, 253, 0.18) 50%,
    rgba(168, 85, 247, 0.12) 55%,
    transparent 75%
  );
  background-size: 200% 100%;
}

.portrait-ai-textarea-wrap.is-shimmer .portrait-ai-shimmer {
  opacity: 1;
  animation: portrait-ai-shimmer 1.35s ease-in-out infinite;
}

@keyframes portrait-ai-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.portrait-ai-char-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.35rem;
}

.portrait-ai-char-count {
  font-size: 0.75rem;
  color: rgba(184, 180, 207, 0.65);
}

.portrait-ai-char-count.is-near-limit {
  color: #fbbf24;
}

.portrait-ai-actions {
  display: flex;
  gap: 0.65rem;
  align-items: stretch;
  margin-top: 0.85rem;
}

.portrait-ai-refresh-btn {
  flex-shrink: 0;
  width: 2.75rem;
  border-radius: 12px;
  border: 1px solid rgba(168, 85, 247, 0.45);
  background: rgba(255, 255, 255, 0.04);
  color: #ddd6fe;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.portrait-ai-refresh-btn:hover:not(:disabled) {
  background: rgba(168, 85, 247, 0.15);
}

.portrait-ai-generate-btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 0.65rem 1rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, #9333ea, #7c3aed 55%, #6d28d9);
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.35);
}

.portrait-ai-generate-btn:disabled,
.portrait-ai-refresh-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.portrait-ai-commit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.portrait-ai-commit-actions.d-none {
  display: none;
}

.portrait-ai-use-btn {
  flex: 1 1 100%;
  border: none;
  border-radius: 12px;
  padding: 0.65rem 1rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, #059669, #047857);
}

.portrait-ai-regenerate-btn,
.portrait-ai-cancel-preview-btn {
  flex: 1;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid rgba(168, 85, 247, 0.35);
  background: rgba(255, 255, 255, 0.04);
  color: #e9d5ff;
}

.portrait-ai-preview-img.is-visible {
  image-rendering: auto;
}

.portrait-ai-footnote,
.portrait-ai-switch-upload {
  font-size: 0.82rem;
  color: rgba(184, 180, 207, 0.75);
  margin-top: 0.75rem;
}

.portrait-ai-switch-upload {
  border: none;
  background: none;
  color: #c4b5fd;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.portrait-ai-status {
  font-size: 0.85rem;
  color: rgba(184, 180, 207, 0.85);
  margin-top: 0.75rem;
}

.portrait-ai-status-card {
  border-radius: 12px;
  padding: 0;
  border: 1px solid transparent;
  transition: border-color 0.2s ease, background 0.2s ease, padding 0.2s ease;
}

.portrait-ai-status-card.is-visible {
  padding: 0.65rem 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(168, 85, 247, 0.2);
}

.portrait-ai-status-card.is-loading.is-visible {
  border-color: rgba(168, 85, 247, 0.35);
}

.portrait-ai-status-card.is-error.is-visible {
  background: rgba(127, 29, 29, 0.18);
  border-color: rgba(248, 113, 113, 0.45);
}

.portrait-ai-retry-btn {
  margin-top: 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(251, 191, 36, 0.55);
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
}

.portrait-fade-in {
  animation: portrait-fade-in 0.45s ease;
}

@keyframes portrait-fade-in {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.portrait-ai-status-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 1.75rem;
}

.portrait-ai-spinner {
  display: none;
  flex-shrink: 0;
  width: 1.35rem;
  height: 1.35rem;
  border: 2px solid rgba(168, 85, 247, 0.25);
  border-top-color: #c084fc;
  border-radius: 50%;
}

.portrait-ai-spinner.is-active {
  display: inline-block;
  animation: portrait-ai-spin 0.85s linear infinite;
}

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

.portrait-ai-status.is-loading .portrait-ai-status-text {
  color: #e9d5ff;
}

.portrait-ai-status.is-error {
  color: #f87171;
}

.portrait-ai-status.is-error .portrait-ai-status-text {
  color: #f87171;
}

.portrait-source-modal {
  position: fixed;
  inset: 0;
  z-index: 10002;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  padding: 1rem;
}

.portrait-source-modal.is-open {
  display: flex;
}

.portrait-source-card {
  position: relative;
  width: min(520px, 100%);
  background: #1a1430;
  border: 1px solid rgba(168, 85, 247, 0.35);
  border-radius: 16px;
  padding: 1.25rem 1.25rem 1rem;
  color: #f3efff;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.portrait-source-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  border: none;
  background: transparent;
  color: #c4b5fd;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.portrait-source-lead {
  opacity: 0.85;
  margin-bottom: 1rem;
}

.portrait-source-actions {
  display: block;
  margin-bottom: 0.25rem;
}

.portrait-ai-panel {
  margin-top: 1rem;
  text-align: left;
}

.avatar-card-btn--ai {
  background: rgba(168, 85, 247, 0.18);
  border-color: rgba(168, 85, 247, 0.55);
}

.avatar-size-hint {
  font-size: 0.78rem;
  color: rgba(184, 180, 207, 0.6);
  margin-top: 0.25rem;
}

/* In-game avatar crop overlay (shown when changing photo) */
.avatar-crop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10001;
  /* Above avatar card overlay (z-index: 10000) */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}

.avatar-crop-zone {
  width: 512px;
  height: 512px;
  max-width: calc(100vw - 32px);
  /* Cap height by viewport HEIGHT (not width) so the 512px zone never crowds
     the hint + actions row off-screen on short/landscape viewports.
     The 120px reservation covers: 1rem gap (16) + hint (~24) + 1rem gap (16)
     + actions (~48) + 16px buffer. */
  max-height: min(calc(100vw - 32px), calc(100vh - 120px));
  border-radius: 50%;
  border: 2px solid rgba(138, 100, 255, 0.5);
  position: relative;
  overflow: hidden;
}

.avatar-crop-actions {
  display: flex;
  gap: 0.75rem;
}

.avatar-upload-zone {
  width: 270px;
  height: 270px;
  max-width: min(55vw, 100%);
  max-height: min(55vw, 100%);
  margin: 0.5rem auto;
  border-radius: 50%;
  border: 3px dashed rgba(168, 85, 247, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: rgba(255, 255, 255, 0.03);
  position: relative;
  overflow: hidden;
}

.avatar-upload-zone:hover {
  border-color: rgba(168, 85, 247, 0.7);
  background: rgba(168, 85, 247, 0.08);
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.15);
}

.avatar-upload-zone.drag-over {
  border-color: #a855f7;
  background: rgba(168, 85, 247, 0.15);
  box-shadow: 0 0 32px rgba(168, 85, 247, 0.3);
  transform: scale(1.02);
}

.avatar-upload-zone.has-preview {
  border-style: solid;
  border-color: rgba(168, 85, 247, 0.5);
}

.avatar-upload-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  opacity: 0.7;
}

.avatar-upload-text {
  font-size: 0.85rem;
  opacity: 0.6;
}

.avatar-upload-zone.has-preview .avatar-upload-icon,
.avatar-upload-zone.has-preview .avatar-upload-text {
  display: none;
}

/* Hidden file input */
.avatar-file-input {
  display: none;
}

/* Preview inside upload zone */
.avatar-upload-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: none;
}

.avatar-upload-zone.has-preview .avatar-upload-preview {
  display: block;
}

/* Change photo chip (wizard upload crop — keeps face visible) */
.avatar-change-btn {
  position: absolute;
  bottom: 8px;
  left: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.88);
  color: white;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease;
  z-index: 3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.avatar-upload-zone.has-preview .avatar-change-btn {
  display: flex;
}

.avatar-change-btn:hover,
.avatar-change-btn:focus-visible {
  transform: scale(1.1);
  background: rgba(88, 28, 135, 0.92);
  outline: 2px solid rgba(168, 85, 247, 0.85);
  outline-offset: 2px;
}

/* Remove button overlay */
.avatar-remove-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  z-index: 2;
}

.avatar-upload-zone.has-preview .avatar-remove-btn {
  display: flex;
}

.avatar-remove-btn:hover {
  transform: scale(1.1);
  background: #ef4444;
}

/* Upload constraints text */
.avatar-constraints {
  font-size: 0.8rem;
  opacity: 0.5;
  margin-top: 0.5rem;
}

/* Skip hint */
.avatar-skip-hint {
  margin-top: 1rem;
  font-size: 0.85rem;
  opacity: 0.6;
}

/* ---------- In-Game Avatar Thumbnail ---------- */

.player-avatar-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(168, 85, 247, 0.4);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.player-avatar-thumb:hover {
  border-color: #a855f7;
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
  transform: scale(1.1);
}

/* Default placeholder when no avatar */
.player-avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px dashed rgba(168, 85, 247, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  opacity: 0.6;
}

/* Player message row with avatar */
.player-message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 0.5rem;
}

/* ---------- Expanded Avatar Card (Overlay) ---------- */

.avatar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: avatarFadeIn 0.2s ease;
}

.avatar-overlay.visible {
  display: flex;
}

@keyframes avatarFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.avatar-card {
  background: linear-gradient(145deg, rgba(22, 26, 53, 0.98), rgba(14, 8, 32, 0.98));
  border: 1px solid rgba(168, 85, 247, 0.4);
  border-radius: 16px;
  padding: 1.5rem;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.5), 0 0 32px rgba(168, 85, 247, 0.15);
  position: relative;
}

.avatar-card-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.avatar-card-close:hover {
  background: rgba(239, 68, 68, 0.4);
  border-color: rgba(239, 68, 68, 0.5);
  color: white;
}

.avatar-card-image {
  width: 340px;
  height: 340px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(168, 85, 247, 0.5);
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.2);
  margin-bottom: 1rem;
}

.avatar-card-name {
  font-size: 1.25rem;
  font-weight: 600;
  color: #f0ecff;
  margin-bottom: 0.25rem;
}

.avatar-card-class {
  font-size: 0.9rem;
  color: #b8b4cf;
  margin-bottom: 0.75rem;
}

.avatar-card-stats {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.avatar-stat {
  background: rgba(168, 85, 247, 0.1);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: #d4a843;
}

.avatar-stat-label {
  font-size: 0.7rem;
  color: #8a86a8;
  display: block;
}

/* ---------- Header HUD avatar ---------- */
.header-avatar-slot {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  position: relative;
  z-index: 1060;
  margin-top: 0;
  margin-bottom: 0;
}

.game-avatar-float {
  position: relative;
  z-index: 1060;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
  display: inline-flex;
  align-items: center;
}

.game-avatar-float img {
  width: 66px;
  height: 66px;
  max-width: 16vw;
  max-height: 16vw;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 15%;
  border: 3px solid rgba(168, 85, 247, 0.8);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7), 0 0 20px rgba(168, 85, 247, 0.45);
  background: #120e24;
  transition: all 0.2s ease;
}

.game-avatar-float:hover img {
  border-color: #a855f7;
  box-shadow: 0 0 24px rgba(168, 85, 247, 0.65);
  transform: scale(1.04);
}

/* --- Avatar card action buttons (Change Photo / Remove) --- */
.avatar-card-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
}

.avatar-card-btn {
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid rgba(168, 85, 247, 0.3);
  background: rgba(168, 85, 247, 0.1);
  color: #d4c4f0;
}

.avatar-card-btn:hover {
  background: rgba(168, 85, 247, 0.25);
  border-color: rgba(168, 85, 247, 0.5);
}

.avatar-card-btn--remove {
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
  color: #f0a0a0;
}

.avatar-card-btn--remove:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
}

/* Empty-state "Add Avatar" placeholder circle — mirrors the populated
 * .game-avatar-float img aesthetic (66px class target, purple border,
 * glow shadow) but uses a dashed ring + faint tint to signal "no avatar yet" so
 * users see the affordance before clicking. Click + camera-icon both open the
 * file picker exactly like the old rectangular button did.
 */
.game-avatar-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 66px;
  height: 66px;
  max-width: 16vw;
  max-height: 16vw;
  border-radius: 50%;
  border: 2px dashed rgba(168, 85, 247, 0.55);
  background: rgba(168, 85, 247, 0.08);
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.55),
    0 0 16px rgba(168, 85, 247, 0.25);
  color: #d4c4f0;
  cursor: pointer;
  font: inherit;
  padding: 0;
  flex-shrink: 0;
  position: relative;
  z-index: 1060;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}

.game-avatar-add-btn:hover {
  background: rgba(168, 85, 247, 0.18);
  border-color: rgba(168, 85, 247, 0.85);
  border-style: solid;
  transform: scale(1.04);
  box-shadow:
    0 0 24px rgba(168, 85, 247, 0.55),
    0 4px 20px rgba(0, 0, 0, 0.55);
}

.game-avatar-add-btn:active {
  transform: scale(0.96);
  background: rgba(168, 85, 247, 0.22);
}

.game-avatar-add-btn:focus {
  outline: none;
}

.game-avatar-add-btn:focus-visible {
  outline: 2px solid #a855f7;
  outline-offset: 3px;
}

.game-avatar-add-btn[disabled] {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

.game-avatar-add-btn .add-btn-icon {
  display: inline-flex;
  pointer-events: none;
}

.game-avatar-add-btn .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile header keeps the same scaled avatar target as desktop. */
@media (max-width: 576px) {
  .game-avatar-float img {
    width: 66px;
    height: 66px;
    max-width: 16vw;
    max-height: 16vw;
    border: 2.5px solid rgba(168, 85, 247, 0.8);
  }

  .game-avatar-add-btn {
    width: 66px;
    height: 66px;
    max-width: 16vw;
    max-height: 16vw;
  }

  .game-avatar-add-btn .add-btn-icon svg {
    width: 20px;
    height: 20px;
  }

  .avatar-card {
    max-width: 320px;
    padding: 1.25rem;
  }

  .avatar-card-image {
    width: 200px;
    height: 200px;
  }

  .avatar-card-name {
    font-size: 1.1rem;
  }

  .avatar-stat {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
  }
}

/* -- Toast notification -- */
.avatar-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10001;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: avatarToastIn 0.3s ease, avatarToastOut 0.3s ease 2.7s forwards;
}

.avatar-toast.success {
  background: rgba(34, 197, 94, 0.9);
}

.avatar-toast.error {
  background: rgba(239, 68, 68, 0.9);
}

@keyframes avatarToastIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes avatarToastOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

/* ---------- Mobile Responsive ---------- */
@media (max-width: 576px) {
  .portrait-source-card {
    max-height: min(92vh, 720px);
    overflow-y: auto;
  }

  .portrait-ai-layout {
    grid-template-columns: 1fr;
  }

  /* Matched min() width/height keeps the mobile preview ring circular. */
  .portrait-ai-preview-ring {
    width: min(180px, 42vw, 100%);
    height: min(180px, 42vw, 100%);
    aspect-ratio: 1;
  }

  .avatar-source-segment,
  .portrait-source-segment {
    max-width: 100%;
  }

  .avatar-source-segment-btn {
    font-size: 0.75rem;
    padding: 0.5rem 0.35rem;
  }

  .avatar-upload-zone {
    width: 240px;
    height: 240px;
    max-width: min(55vw, 100%);
    max-height: min(55vw, 100%);
  }

  .avatar-card {
    max-width: 320px;
  }

  .avatar-card-image {
    width: 200px;
    height: 200px;
  }

  .avatar-crop-zone {
    width: 200px;
    height: 200px;
  }
}

/* Spinner for the Add Avatar upload-in-flight state */
@keyframes avatar-add-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
