/* Player portrait cards */
.player-portrait {
  --foil-opacity: 0;
  --tilt-x: 0deg;
  --tilt-y: 0deg;
  --holo-x: 42%;
  --holo-y: 48%;
  --holo-x2: 55%;
  --holo-y2: 40%;
  --holo-x3: 60%;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  cursor: default;
}

.player-portrait[type="button"],
button.player-portrait {
  cursor: pointer;
}

.player-portrait.portrait-sm { width: 5.5rem; }
.player-portrait.portrait-md { width: 7.5rem; }
.player-portrait.portrait-lg { width: 11rem; }

.portrait-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.portrait-art {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 6;
  border-radius: 0.35rem;
  overflow: hidden;
  background: #1a1520;
  transform: perspective(800px) rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transform-style: preserve-3d;
}

.portrait-image {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.portrait-art.has-background .portrait-image {
  object-fit: contain;
  object-position: center bottom;
}

.portrait-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.portrait-foil {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  opacity: var(--foil-opacity, 0);
  overflow: hidden;
  isolation: isolate;
  mix-blend-mode: color-dodge;
}

.portrait-foil.foil-none {
  display: none;
}

.portrait-foil-rainbow,
.portrait-foil-grating,
.portrait-foil-glint {
  position: absolute;
  inset: -35%;
  will-change: background-position, transform;
}

/* Diagonal iridescent bands — sparse (~10% color), parallax via --holo-x / --holo-y */
.portrait-foil-rainbow {
  background-image: repeating-linear-gradient(
    125deg,
    transparent 0%,
    transparent 42%,
    #ff1b8d 43.2%,
    #7c3aed 45%,
    #06b6d4 46.8%,
    #f97316 48.2%,
    transparent 49.5%,
    transparent 100%
  );
  background-size: 280% 280%;
  background-position: var(--holo-x, 42%) var(--holo-y, 48%);
  filter: saturate(1.4) contrast(1.15) brightness(1.05);
  opacity: 0.9;
}

.portrait-foil.foil-silver .portrait-foil-rainbow {
  background-image: repeating-linear-gradient(
    125deg,
    transparent 0%,
    transparent 42%,
    #f8fafc 43.2%,
    #cbd5e1 45%,
    #94a3b8 46.5%,
    #e2e8f0 48%,
    transparent 49.5%,
    transparent 100%
  );
  filter: saturate(0.3) contrast(1.3) brightness(1.15);
}

.portrait-foil.foil-gold .portrait-foil-rainbow {
  background-image: repeating-linear-gradient(
    125deg,
    transparent 0%,
    transparent 42%,
    #fff7ed 43.2%,
    #fbbf24 45%,
    #f59e0b 46.5%,
    #fdba74 48%,
    transparent 49.5%,
    transparent 100%
  );
  filter: saturate(1.15) contrast(1.15) brightness(1.08);
}

.portrait-foil.foil-bismuth .portrait-foil-rainbow {
  background-image: repeating-linear-gradient(
    125deg,
    transparent 0%,
    transparent 42%,
    #ff00aa 43%,
    #7b2fff 44.5%,
    #00e5ff 46%,
    #d4ff00 47.2%,
    #ff8800 48.4%,
    transparent 49.5%,
    transparent 100%
  );
  filter: saturate(1.55) contrast(1.2) brightness(1.08);
}

/* Fine diffraction / moiré grating — shifts at a different rate for parallax depth */
.portrait-foil-grating {
  background-image:
    repeating-linear-gradient(
      125deg,
      rgba(255, 255, 255, 0) 0px,
      rgba(255, 255, 255, 0.28) 0.7px,
      rgba(0, 0, 0, 0.35) 1.4px,
      rgba(255, 255, 255, 0.12) 2.1px,
      rgba(255, 255, 255, 0) 3.5px,
      rgba(255, 255, 255, 0) 5.5px
    ),
    repeating-linear-gradient(
      55deg,
      rgba(255, 255, 255, 0) 0px,
      rgba(255, 255, 255, 0.1) 0.6px,
      rgba(255, 255, 255, 0) 2.2px
    );
  background-size: 11px 11px, 6px 6px;
  background-position: var(--holo-x2, 55%) var(--holo-y2, 40%), var(--holo-x3, 60%) var(--holo-y, 48%);
  mix-blend-mode: overlay;
  opacity: 0.55;
  /* Mask grating to the sparse band zone so it doesn't wash the whole card */
  -webkit-mask-image: repeating-linear-gradient(
    125deg,
    transparent 0%,
    transparent 42%,
    #000 43%,
    #000 49%,
    transparent 50%,
    transparent 100%
  );
  mask-image: repeating-linear-gradient(
    125deg,
    transparent 0%,
    transparent 42%,
    #000 43%,
    #000 49%,
    transparent 50%,
    transparent 100%
  );
  -webkit-mask-size: 280% 280%;
  mask-size: 280% 280%;
  -webkit-mask-position: var(--holo-x, 42%) var(--holo-y, 48%);
  mask-position: var(--holo-x, 42%) var(--holo-y, 48%);
  transform: translate3d(0, 0, 0);
}

/* Specular glint band — thin sweep only */
.portrait-foil-glint {
  inset: 0;
  background:
    radial-gradient(
      ellipse 28% 18% at var(--holo-x3, 60%) var(--holo-y2, 40%),
      rgba(255, 255, 255, 0.7) 0%,
      rgba(255, 255, 255, 0.12) 40%,
      transparent 70%
    ),
    linear-gradient(
      115deg,
      transparent 44%,
      rgba(255, 255, 255, 0.5) 49%,
      transparent 54%
    );
  background-size: 100% 100%, 240% 240%;
  background-position: center, var(--holo-x, 42%) var(--holo-y, 48%);
  mix-blend-mode: soft-light;
  opacity: 0.75;
}

/* Editor preview: animate holographic parallax without rotating the card */
.player-portrait.foil-preview .portrait-foil-rainbow {
  animation: holo-rainbow-move 3.2s ease-in-out infinite;
}

.player-portrait.foil-preview .portrait-foil-grating {
  animation: holo-grating-move 3.2s ease-in-out infinite;
  -webkit-mask-size: 280% 280%;
  mask-size: 280% 280%;
}

.player-portrait.foil-preview .portrait-foil-glint {
  animation: holo-glint-move 3.2s ease-in-out infinite;
}

@keyframes holo-rainbow-move {
  0%, 100% { background-position: 18% 32%; }
  50% { background-position: 82% 68%; }
}

@keyframes holo-grating-move {
  0%, 100% { background-position: 28% 55%, 72% 40%; }
  50% { background-position: 88% 30%, 20% 70%; }
}

@keyframes holo-glint-move {
  0%, 100% { background-position: center, 20% 35%; }
  50% { background-position: center, 80% 65%; }
}

.portrait-border {
  pointer-events: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.portrait-sticker {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 3;
  width: 28%;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55));
}

.portrait-sticker img {
  width: 100%;
  height: auto;
  display: block;
}

.portrait-sticker-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 9999px;
  font-size: 0.85rem;
}

.portrait-sm .portrait-sticker-icon { width: 1.25rem; height: 1.25rem; font-size: 0.65rem; }
.portrait-lg .portrait-sticker-icon { width: 2.25rem; height: 2.25rem; font-size: 1.1rem; }

.portrait-praised-mark {
  position: absolute;
  right: 4%;
  bottom: 6%;
  width: 36%;
  z-index: 4;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
}

.portrait-banner {
  display: flex;
  align-items: stretch;
  margin-top: -0.35rem;
  z-index: 2;
  min-height: 1.4rem;
}

.portrait-banner .banner-slice {
  height: 1.4rem;
  width: 0.7rem;
  flex: none;
  object-fit: fill;
}

.portrait-banner .banner-center {
  flex: 1;
  min-width: 0;
  background-repeat: repeat-x;
  background-size: auto 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.15rem;
}

.portrait-banner .banner-name {
  font-size: 0.7rem;
  font-weight: 600;
  color: #3b2a14;
  line-height: 1.1;
  text-align: center;
}

.portrait-banner .banner-name-gold {
  font-family: "Risque", "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: #4a3008;
  text-shadow: 0 1px 0 rgba(255, 236, 170, 0.95);
}

.portrait-banner .banner-name-wood {
  font-family: "Peralta", Georgia, serif;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: #241208;
  text-shadow: 0 1px 0 rgba(232, 196, 140, 0.55);
}

.portrait-banner.truncate-name .banner-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.banner-name-plain {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
}

.portrait-lg .portrait-banner .banner-name { font-size: 0.9rem; }
.portrait-lg .portrait-banner .banner-name-gold,
.portrait-lg .portrait-banner .banner-name-wood { font-size: 1rem; }
.portrait-lg .portrait-banner .banner-slice { height: 1.75rem; width: 0.9rem; }
.portrait-lg .portrait-banner .banner-center { min-height: 1.75rem; }
.portrait-sm .portrait-banner .banner-name { font-size: 0.6rem; }
.portrait-sm .portrait-banner .banner-name-gold,
.portrait-sm .portrait-banner .banner-name-wood { font-size: 0.65rem; }
.portrait-sm .portrait-banner .banner-slice { height: 1.1rem; width: 0.55rem; }

/* Card stage (praise theater) — lives in modal-layer outside parallax perspective */
.portrait-stage-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  cursor: pointer;
  perspective: 1200px;
}

.portrait-stage-card {
  --tilt-x: 0deg;
  --tilt-y: 0deg;
  --holo-x: 42%;
  --holo-y: 48%;
  --holo-x2: 55%;
  --holo-y2: 40%;
  --holo-x3: 60%;
  --fly-x: 0px;
  --fly-y: 0px;
  --fly-scale: 0.45;
  position: relative;
  width: min(72vw, 280px);
  transform-style: preserve-3d;
  cursor: pointer;
}

.portrait-stage-card.is-flying {
  animation: portrait-fly-out 0.75s cubic-bezier(0.2, 0.85, 0.25, 1) forwards;
}

.portrait-stage-card .player-portrait {
  width: 100%;
}

.portrait-stage-slap {
  position: absolute;
  inset: 10% 8% auto;
  width: 84%;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transform: scale(2.2) rotate(-18deg);
}

.portrait-stage-slap.show {
  animation: talons-slap 0.45s cubic-bezier(0.1, 1.4, 0.4, 1) forwards;
}

@keyframes portrait-fly-out {
  0% {
    transform: translate(var(--fly-x), var(--fly-y)) scale(var(--fly-scale)) rotateY(-130deg);
    opacity: 0.55;
  }
  60% {
    transform: translate(0, 0) scale(1.06) rotateY(12deg);
    opacity: 1;
  }
  100% {
    transform: translate(0, 0) scale(1) rotateY(0deg);
    opacity: 1;
  }
}

@keyframes talons-slap {
  0% { opacity: 0; transform: scale(2.4) rotate(-24deg) translateY(-20%); }
  60% { opacity: 1; transform: scale(1.05) rotate(-6deg) translateY(0); }
  100% { opacity: 0.92; transform: scale(1) rotate(-8deg); }
}

.portrait-stage-hint {
  position: absolute;
  bottom: 1.5rem;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255,255,255,0.75);
  font-size: 0.85rem;
  pointer-events: none;
  padding: 0 1rem;
}

/* Portrait editor as a full modal page (view-stack swap from profile) */
.portrait-editor-page {
  display: flex;
  flex-direction: column;
  height: min(72vh, 40rem);
  min-height: 24rem;
  margin: -0.25rem;
}

.portrait-editor-header {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.portrait-editor-header h3 {
  justify-self: center;
  margin: 0;
}

.portrait-editor-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.875rem;
  opacity: 0.85;
}

.portrait-editor-back:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

.portrait-editor-preview {
  flex: none;
  display: flex;
  justify-content: center;
  padding: 0.85rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.portrait-editor-controls {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.85rem 0.15rem 0.85rem 0;
}

.portrait-editor-footer {
  flex: none;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
