/* Pirate Coin Component Styles - Using Real Coin Images */

/* Interactive Physics Coin */
.interactive-coin {
    position: absolute;
    width: 120px;
    height: 120px;
    cursor: grab;
    z-index: 1000;
    transition: none;
    transform-style: preserve-3d;
    user-select: none;
}

.interactive-coin:active {
    cursor: grabbing;
}

.interactive-coin.spinning {
    animation: spinCoin 0.1s linear infinite;
}

@keyframes spinCoin {
    from {
        transform: rotateY(0deg);
    }

    to {
        transform: rotateY(360deg);
    }
}

.pirate-coin {
    /* CSS Custom Properties for customization */
    --coin-size: 8em;
    --coin-flip-speed: 4s;
    --coin-flip-easing: ease-in-out;
    --coin-margin: 1rem;
    --coin-glow-color: rgba(255, 215, 0, 0.6);
    --coin-glow-size: 8px;
    --coin-border-width: 2px;
    --coin-border-color: rgba(139, 69, 19, 0.3);
    --coin-edge-thickness: 8px;
    --coin-edge-color: #b8860b;

    width: var(--coin-size);
    height: var(--coin-size);
    position: relative;
    margin: var(--coin-margin);
    perspective: 1000px;
    cursor: pointer;
    display: inline-block;
    transform-style: preserve-3d;
}

/* Coin edge effect */
.pirate-coin::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--coin-size);
    height: var(--coin-edge-thickness);
    background: linear-gradient(180deg,
            #ffd700 0%,
            var(--coin-edge-color) 20%,
            #8b7355 50%,
            var(--coin-edge-color) 80%,
            #ffd700 100%);
    border-radius: var(--coin-edge-thickness);
    transform: translate(-50%, -50%) rotateX(90deg);
    transform-origin: center;
    opacity: 0;
    transition: opacity var(--coin-flip-speed) var(--coin-flip-easing);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.3),
        inset 0 1px 1px rgba(255, 255, 255, 0.2);
}

.coin-front,
.coin-back {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    backface-visibility: hidden;
    transition: transform var(--coin-flip-speed) var(--coin-flip-easing);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.4),
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    border: var(--coin-border-width) solid var(--coin-border-color);
}

.coin-front {
    background-image: url('/img/pirate_coin_heads.png');
}

.coin-back {
    background-image: url('/img/pirate_coin_tails.png');
    transform: rotateY(180deg);
}

.pirate-coin:hover .coin-front {
    transform: rotateY(180deg) translateZ(20px) scale(1.1);
    box-shadow:
        0 8px 16px rgba(0, 0, 0, 0.5),
        0 4px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
}

.pirate-coin:hover .coin-back {
    transform: rotateY(0) translateZ(20px) scale(1.1);
    box-shadow:
        0 8px 16px rgba(0, 0, 0, 0.5),
        0 4px 8px rgba(0, 0, 0, 0.3),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
}

/* Optional: Add a subtle glow effect on hover */
.pirate-coin:hover {
    filter: drop-shadow(0 0 var(--coin-glow-size) var(--coin-glow-color));
    transform: translateY(-5px);
}

/* Show edge during flip animation */
.pirate-coin:hover::before {
    opacity: 1;
    animation: edgeFlash var(--coin-flip-speed) var(--coin-flip-easing);
}

/* Keyframes for edge visibility timing */
@keyframes edgeFlash {
    0% {
        opacity: 0;
    }

    25% {
        opacity: 0.3;
    }

    50% {
        opacity: 1;
    }

    75% {
        opacity: 0.3;
    }

    100% {
        opacity: 0;
    }
}

/* Preset size variants using custom properties */
.pirate-coin.small {
    --coin-size: 80px;
    --coin-margin: 0.5rem;
}

.pirate-coin.large {
    --coin-size: 160px;
    --coin-margin: 1.5rem;
}

.pirate-coin.huge {
    --coin-size: 200px;
    --coin-margin: 2rem;
}

/* Speed variants */
.pirate-coin.fast {
    --coin-flip-speed: 0.4s;
}

.pirate-coin.slow {
    --coin-flip-speed: 1.2s;
}

.pirate-coin.very-slow {
    --coin-flip-speed: 2s;
}

/* New template structure support */
.coin-container {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform var(--coin-flip-speed) var(--coin-flip-easing);
}

.coin-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    backface-visibility: hidden;
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.4),
        0 2px 4px rgba(0, 0, 0, 0.2),
        inset 0 1px 2px rgba(255, 255, 255, 0.1);
    border: var(--coin-border-width) solid var(--coin-border-color);
}

.coin-face img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.coin-face.front {
    transform: rotateZ(0deg);
}

.coin-face.back {
    transform: rotateY(180deg);
}

/* Interactive coin specific styles */
.pirate-coin.interactive {
    position: relative;
    display: inline-block;
    transition: transform 0.3s ease;
    animation: subtlePulse 3s ease-in-out infinite;
}

@keyframes subtlePulse {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.3);
        transform: scale(1);
    }

    50% {
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
        transform: scale(1.05);
    }
}

.pirate-coin.interactive:hover {
    transform: scale(1.1) translateY(-5px);
}

.pirate-coin.interactive:hover .coin-container {
    animation: hoverFlip 1s ease-in-out infinite alternate;
}

@keyframes hoverFlip {
    0% {
        transform: rotateY(0deg);
    }

    100% {
        transform: rotateY(15deg);
    }
}

/* Click hint */
.coin-hint {
    position: absolute;
    top: 110%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.pirate-coin.interactive:hover .coin-hint {
    opacity: 1;
}

.hint-text {
    background: rgba(139, 69, 19, 0.9);
    color: #ffd700;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Static coin styles */
.pirate-coin.static {
    position: relative;
    display: inline-block;
}

.pirate-coin.static:hover .coin-container {
    transform: rotateY(180deg);
}