.board-solo-wrapper,
.board-wrapper {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  justify-content: flex-end;
  align-items: center;

  .deck {
    width: 120px;
    height: 168px;
    background-color: #444;
    background-image: url("../Magic_card_back.jpg");
    background-size: contain;
    border-radius: 5%;
    position: absolute;
    top: 20px;
    right: 20px;
  }

  .buttons {
    display: flex;
    flex-direction: row;
    margin-bottom: 0.4em;

    .button {
      margin: 20px;
      padding: 10px 20px;
      font-size: 16px;
      cursor: pointer;
      user-select: none;
    }

    .show-chat-button {
      display: none;
    }
  }

  .hand {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 170px;
    padding: 0 10px;
    position: relative;
    bottom: 10px;

    .card {
      // Never squeeze hand cards (tiles the background image);
      // updateHandOverlap fans them instead
      flex-shrink: 0;
    }
  }

  .player-board {
    width: 100%;
    height: 100%;
    // Same look as the multi board's default slate theme (the multi board
    // unsets this and paints .multi-wrapper instead — see multi.less)
    background: radial-gradient(
        120% 90% at 50% 40%,
        rgba(255, 255, 255, 0.07),
        transparent 60%
      ),
      linear-gradient(165deg, #363c44, #262b31 55%, #1e2227);
  }

  .card {
    width: 120px;
    height: 168px;
    position: relative;
    background-color: #444;
    background-image: url("../Magic_card_back.jpg");
    background-size: contain;
    background-repeat: no-repeat;
    border: 1px solid #ccc;
    border-radius: 10px;
    margin: 0 2px;
    transition: transform 0.5s ease, opacity 0.5s ease;
    cursor: pointer;
    box-shadow: 0 0 0 0 #778899;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;

    &.played {
      z-index: 99;
    }

    &.tapped {
      transform: rotate(90deg);
    }

    &:hover {
      // Only apply scale if the card is NOT tapped
      &:not(.tapped, .played) {
        transform: scale(1.05);
        box-shadow: 0 12px 19px rgba(0, 0, 0, 0.9),
          0 0 40px rgba(0, 0, 0, 0.1) inset;
        z-index: 9999999;
      }
      &.tapped {
        transform: scale(1.05) rotate(90deg);
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3),
          0 0 40px rgba(0, 0, 0, 0.1) inset;
      }
    }
  }

  // Enhanced card movement effects
  &.dragging-with-trail {
    position: relative !important;
    z-index: 50000 !important;
    transform: scale(1.1) !important;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4) !important;
    border: 3px solid rgba(255, 255, 255, 0.8) !important;
    transition: none !important; // Disable transitions during drag for smooth movement
    
    // Add subtle wiggle animation for inertia effect
    animation: cardWiggle 0.15s ease-in-out infinite alternate;
    
    // Trail effect - pseudo-elements create afterimage
    &::before,
    &::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: inherit;
      background-size: inherit;
      border-radius: inherit;
      opacity: 0.3;
      pointer-events: none;
      z-index: -1;
      transition: opacity 0.3s ease;
    }
    
    &::before {
      transform: translate(-4px, -4px);
      opacity: 0.15;
    }
    
    &::after {
      transform: translate(-8px, -8px);
      opacity: 0.08;
    }
  }

  // Card being played by opponent - comes from above with scale effect.
  // The card may carry a static rotation (is-opposite = 180°, tapped = 90°,
  // both = 270°). A CSS animation replaces the element's whole `transform`,
  // so the keyframes must bake that rotation in — otherwise the card renders
  // un-rotated for the animation's 0.8s and then snaps to its rotation when
  // the class is removed (looked like the card flipping into place).
  &.opponent-card-played {
    animation: opponentCardPlay 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
    z-index: 10000 !important;

    &.tapped {
      animation-name: opponentCardPlayTapped !important;
    }
    &.is-opposite {
      animation-name: opponentCardPlayOpposite !important;
    }
    &.is-opposite.tapped {
      animation-name: opponentCardPlayOppositeTapped !important;
    }
  }

  // Reduced effect for normal movement - just white border
  &.moving-card {
    border: 2px solid rgba(255, 255, 255, 0.6) !important;
    transition: border 0.1s ease !important;
  }

  // Shining effect only for card play events
  &.card-played-shine {
    position: relative;
    
    &::before {
      content: '';
      position: absolute;
      top: -2px;
      left: -2px;
      right: -2px;
      bottom: -2px;
      background: linear-gradient(45deg, 
        transparent, 
        rgba(255, 255, 255, 0.4), 
        transparent, 
        rgba(255, 255, 255, 0.6), 
        transparent
      );
      background-size: 300% 300%;
      border-radius: inherit;
      pointer-events: none;
      z-index: 1;
      animation: cardShine 1.5s ease-in-out;
    }
    
    &::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: inherit;
      border-radius: inherit;
      z-index: 2;
    }
  }
}

// Keyframe animations
@keyframes cardWiggle {
  0% { transform: scale(1.1) rotate(0deg) translate(0px, 0px); }
  50% { transform: scale(1.1) rotate(0.3deg) translate(-0.5px, -0.3px); }
  100% { transform: scale(1.1) rotate(-0.2deg) translate(0.3px, 0.5px); }
}

// The card drops in from above in screen space (translateY outside the
// rotation) while keeping whatever static rotation it carries (@rot, applied
// before scale so it pivots on the card's own centre).
.opponentCardPlayFrames(@rot) {
  0% {
    transform: translateY(-100px) rotate(@rot) scale(1.5);
    opacity: 0.8;
  }
  60% {
    transform: translateY(-10px) rotate(@rot) scale(1.2);
    opacity: 1;
  }
  100% {
    transform: translateY(0) rotate(@rot) scale(1);
    opacity: 1;
  }
}

@keyframes opponentCardPlay {
  .opponentCardPlayFrames(0deg);
}

@keyframes opponentCardPlayTapped {
  .opponentCardPlayFrames(90deg);
}

@keyframes opponentCardPlayOpposite {
  .opponentCardPlayFrames(180deg);
}

@keyframes opponentCardPlayOppositeTapped {
  .opponentCardPlayFrames(270deg);
}

// Battlefield card flip (double-faced turn / art peek). A CSS animation
// replaces the whole `transform`, so — like opponentCardPlay — the card's
// static rotation (tapped 90°, is-opposite 180°, both 270°) is baked in via
// the --flip-base variable set in JS. Single background image, so we hide the
// face edge-on at the midpoint (rotateY 90°), let JS swap the image there, then
// jump to -90° and swing back to 0° so the new face lands un-mirrored.
.card.card-flipping {
  animation: cardFlip 0.45s ease-in-out;
  z-index: 100000 !important;
}

@keyframes cardFlip {
  0% {
    transform: var(--flip-base, rotate(0deg)) perspective(700px) rotateY(0deg);
  }
  49.9% {
    transform: var(--flip-base, rotate(0deg)) perspective(700px) rotateY(90deg);
    filter: brightness(1.5);
  }
  50% {
    transform: var(--flip-base, rotate(0deg)) perspective(700px) rotateY(-90deg);
    filter: brightness(1.5);
  }
  100% {
    transform: var(--flip-base, rotate(0deg)) perspective(700px) rotateY(0deg);
  }
}

@keyframes cardShine {
  0% {
    background-position: -300% -300%;
    opacity: 0;
  }
  50% {
    background-position: 0% 0%;
    opacity: 1;
  }
  100% {
    background-position: 300% 300%;
    opacity: 0;
  }
}

// Placement snapping feedback ------------------------------------------------

// Ghost outline shown at the spot a dragged card is about to snap to. Sits
// just under the dragged card (which rides at z-index 50000) and above the
// rest of the battlefield, and never eats pointer events.
.snap-preview {
  position: absolute;
  border: 2px dashed rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  background: rgba(120, 190, 255, 0.14);
  box-shadow: 0 0 14px 2px rgba(90, 170, 255, 0.55),
    0 0 0 1px rgba(90, 170, 255, 0.35) inset;
  pointer-events: none;
  z-index: 49999;
  display: none;
  animation: snapPreviewPulse 0.9s ease-in-out infinite;
}

@keyframes snapPreviewPulse {
  0%,
  100% {
    box-shadow: 0 0 12px 1px rgba(90, 170, 255, 0.45),
      0 0 0 1px rgba(90, 170, 255, 0.3) inset;
  }
  50% {
    box-shadow: 0 0 20px 4px rgba(90, 170, 255, 0.75),
      0 0 0 1px rgba(90, 170, 255, 0.5) inset;
  }
}

// A card gliding into its snapped position on release (see animateSnapInto):
// briefly transition left/top so the alignment reads as a click-into-place.
.card.card-snapping {
  transition: left 0.18s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.18s cubic-bezier(0.22, 1, 0.36, 1), transform 0.5s ease,
    opacity 0.5s ease !important;
}

// The top card of a full battlefield stack (one card burying another —
// free placement, a restored save): layered offset edges peeking out
// bottom-right, the same "pile" language as the deck display, so the
// cards underneath are visible at a glance. Box-shadow follows the card's
// border-radius and transform, so a tapped stack keeps its edges too.
// Applied by updateStackedCardIndicators (card-interaction.js).
.card.played.card-stacked {
  box-shadow: 2px 2px 0 0 #3d434b, 3px 3px 0 0 #aab0b8,
    5px 5px 0 0 #343a41, 6px 6px 0 0 #9aa0a8,
    9px 9px 8px rgba(0, 0, 0, 0.45);
}

// Attachment feedback -------------------------------------------------------

// The creature a dragged aura/artifact is hovering over: it will attach onto
// this card on release. Warm gold glow, distinct from the blue neighbor-snap
// preview. No !important so the pulse animation can drive the shadow.
.card.attach-target {
  box-shadow: 0 0 16px 3px rgba(255, 198, 92, 0.85),
    0 0 0 2px rgba(255, 198, 92, 0.9) inset;
  animation: attachTargetPulse 0.85s ease-in-out infinite;
}

@keyframes attachTargetPulse {
  0%,
  100% {
    box-shadow: 0 0 12px 2px rgba(255, 198, 92, 0.55),
      0 0 0 2px rgba(255, 198, 92, 0.7) inset;
  }
  50% {
    box-shadow: 0 0 24px 6px rgba(255, 198, 92, 0.95),
      0 0 0 2px rgba(255, 198, 92, 1) inset;
  }
}
