* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 40px;
    min-height: 100vh;
    background: #f2f2f2;
    font-family: Arial, Helvetica, sans-serif;
    text-align: center;
}

.game {
    width: 400px;
    max-width: 100%;
    margin: auto;
    padding: 30px;
    border-radius: 15px;
    background: white;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}

.game h1 {
    margin-top: 0;
}

.coin-stage {
    position: relative;
    display: grid;
    width: 166px;
    height: 190px;
    margin: 20px auto 0;
    place-items: start center;
    perspective: 900px;
}

.coin {
    position: relative;
    z-index: 1;
    width: 150px;
    height: 150px;
    transform-style: preserve-3d;
}

.coin__inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
}

.coin__face {
    position: absolute;
    display: grid;
    inset: 0;
    place-items: center;
    border: 8px solid goldenrod;
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 28%, #fff3a6 0 6%, transparent 24%),
        radial-gradient(circle at 40% 35%, #ffe166, gold 58%, #c98900 100%);
    box-shadow:
        inset 0 0 0 3px rgba(255, 246, 174, 0.65),
        inset -10px -10px 18px rgba(126, 76, 0, 0.24),
        0 8px 16px rgba(0, 0, 0, 0.2);
    backface-visibility: hidden;
}

.coin__face--tails {
    transform: rotateY(180deg);
}

.coin__ring {
    position: absolute;
    inset: 10px;
    border: 2px dashed rgba(111, 68, 0, 0.45);
    border-radius: 50%;
}

.coin__letter {
    color: #6f4700;
    font-family: Georgia, serif;
    font-size: 64px;
    font-weight: bold;
    text-shadow: 2px 2px rgba(255, 239, 137, 0.8);
}

.coin-shadow {
    position: absolute;
    bottom: 18px;
    width: 92px;
    height: 14px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.25);
    filter: blur(6px);
}

.coin.flip-heads .coin__inner {
    animation: flip-heads 1.25s cubic-bezier(0.24, 0.62, 0.32, 1) forwards;
}

.coin.flip-tails .coin__inner {
    animation: flip-tails 1.3s cubic-bezier(0.24, 0.62, 0.32, 1) forwards;
}

.coin:is(.flip-heads, .flip-tails) {
    animation: coin-toss 1.3s ease-in-out;
}

.coin-stage:has(.coin:is(.flip-heads, .flip-tails)) .coin-shadow {
    animation: shadow-toss 1.3s ease-in-out;
}

.result {
    min-height: 22px;
    margin: 0 0 20px;
    font-weight: bold;
}

.result.is-revealed {
    animation: reveal 0.35s ease-out;
}

.flip-button {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    color: white;
    background: #007bff;
    font-size: 18px;
    cursor: pointer;
    transition: background 160ms ease, transform 160ms ease;
}

.flip-button:hover:not(:disabled) {
    background: #0056b3;
    transform: translateY(-1px);
}

.flip-button:active:not(:disabled) {
    transform: translateY(1px);
}

.flip-button:focus-visible {
    outline: 3px solid #0056b3;
    outline-offset: 3px;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.flip-button:disabled {
    background: gray;
    cursor: wait;
}

.site-footer {
    margin-top: 18px;
    color: #666;
    font-size: 14px;
    letter-spacing: 0.02em;
}

@keyframes flip-heads {
    0% { transform: rotateY(0deg) rotateX(0deg); }
    48% { transform: rotateY(900deg) rotateX(16deg); }
    100% { transform: rotateY(1800deg) rotateX(0deg); }
}

@keyframes flip-tails {
    0% { transform: rotateY(0deg) rotateX(0deg); }
    48% { transform: rotateY(900deg) rotateX(16deg); }
    100% { transform: rotateY(1980deg) rotateX(0deg); }
}

@keyframes coin-toss {
    0%, 100% { transform: translateY(0); }
    48% { transform: translateY(-32px); }
}

@keyframes shadow-toss {
    0%, 100% { opacity: 1; transform: scaleX(1); }
    48% { opacity: 0.3; transform: scaleX(0.5); }
}

@keyframes reveal {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px) {
    body {
        padding: 20px;
    }

    .game {
        padding: 25px 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
