/* ===== COIN TOSS STYLES ===== */

/* ===== ROOT VARIABLES ===== */

/* ===== THEME COLOR CLASSES ===== */
.theme-classic {
    --primary-color: #FF6F61;
    --secondary-color: #FFD5CC;
}

.theme-yes-no {
    --primary-color: #F6C947;
    --secondary-color: #FFF2C5;
}

.theme-true-false {
    --primary-color: #7ED6F3;
    --secondary-color: #D6F6FF;
}

.theme-accept-decline {
    --primary-color: #667EEA;
    --secondary-color: #DDE3FF;
}

.theme-left-right {
    --primary-color: #4CAF50;
    --secondary-color: #DFF5E1;
}

.theme-home-away {
    --primary-color: #B0BEC5;
    --secondary-color: #ECEFF1;
}

.theme-start-wait {
    --primary-color: #B0BEC5;
    --secondary-color: #ECEFF1;
}

.theme-go-stop {
    --primary-color: #B0BEC5;
    --secondary-color: #ECEFF1;
}


/* ===== BODY & LAYOUT ===== */

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link.active {
    color: var(--primary-color);
}

.btn-theme-color {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

/* ===== CARD STYLES ===== */
.card {
    border: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Coin Container */
.coin-container {
    width: 100%;
    max-width: 400px;
    height: 400px;
    margin: 0 auto;
    perspective: 1400px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 10px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 50%;
    /* Round background is clipped by border-radius (background-clip: border-box
       by default), so we no longer need overflow:hidden — and visible overflow
       lets the coin rise on its toss arc. */
    overflow: visible;
}

/* Ground shadow that scales/fades as the coin rises during a toss. */
.coin-shadow {
    position: absolute;
    left: 50%;
    bottom: 44px;
    width: 190px;
    height: 34px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.32) 0%, rgba(0, 0, 0, 0) 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}

.coin-container.tossing .coin-shadow {
    animation: coinTossShadow var(--flip-duration, 3s) cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* 3D Coin */
.coin {
    width: 250px;
    height: 250px;
    position: relative;
    border-radius: 50%;
    transform-style: preserve-3d;
    transition: transform 0.1s;
    cursor: pointer;
    z-index: 1;
}

/* Cylindrical edge — segments are generated by the engine (_buildEdge). Gives
   the coin real thickness so the rim is visible mid-tumble. */
.coin-edge {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    pointer-events: none;
}

.coin-edge span {
    position: absolute;
    left: 50%;
    top: 50%;
    background: linear-gradient(to right, #b8860b, #ffd873 45%, #f3d078 55%, #a9760a);
    box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.35);
}

/* Coin Sides */
.coin-side {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    backface-visibility: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);

    overflow: hidden;
}

.coin-heads {
    background: linear-gradient(145deg, #f3d078, #d4a746);
    color: #fff;
    /* Front face, pushed forward by half the coin depth (the edge fills the gap). */
    transform: rotateX(0deg) translateZ(8px);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    border: 6px solid #ffc107;
    box-shadow: inset -3px -3px 10px rgba(0,0,0,0.1),
                inset 3px 3px 10px rgba(255,255,255,0.4);
}

.coin-tails {
    background: linear-gradient(145deg, #e0e0e0, #b7b7b7);
    color: #fff;
    /* Back face on the X axis: parent rotateX(180) composes with this to land
       upright (end-over-end tumble), pushed back by half the coin depth. */
    transform: rotateX(180deg) translateZ(8px);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    border: 6px solid #616168;
    box-shadow: inset -3px -3px 10px rgba(0,0,0,0.1),
                inset 3px 3px 10px rgba(255,255,255,0.4);
}

.coin-inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    word-break: break-word;
}

/* Background Image Mode */
.coin-bg-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.7;
    z-index: 0;
}

/* Emoji/Image Mode */
.coin-emoji {
    font-size: 4rem;
    margin-bottom: 10px;
    z-index: 2;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.coin-emoji-image {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 50%;
    margin-bottom: 10px;
    border: 4px solid rgba(255, 255, 255, 0.5);
    z-index: 2;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Text Label */
.coin-label {
    font-size: 2rem;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    z-index: 2;
    position: relative;
}

/* Flip Animation — end-over-end tumble (rotateX) on a toss arc.

   ⚠️ THE ROTATION IS LINEAR IN TIME AND NEVER PAUSES. Two earlier versions gave
   the result away and the owner could still read it:
     1. every toss started at rotateX(0) = heads-up, so a whole number of tumbles
        always meant heads (fixed by --flip-start);
     2. an easing curve decelerated the spin into the apex, so the coin visibly
        HUNG at the top showing a readable face, and the flips on the way down
        were slow enough to count — owner: "it stops a little at the top and the
        number of flips it does to come down".
   So the rotation now advances at a CONSTANT angular rate through the whole
   flight (--fr1..--fr7 are evenly-spaced absolute angles computed in JS) and the
   vertical arc is shaped by the keyframe VALUES rather than by timing functions,
   because a timing function would slow the spin as well as the rise. The spin
   finishes as the coin lands at 82%; the rest is the bounce.

   Keep the animation `linear` — any easing here re-creates the hang. */
.coin.flipping {
    animation: flipCoin var(--flip-duration, 2.4s) linear forwards;
}

@keyframes flipCoin {
    0%   { transform: translateY(0) scale(1) rotateX(var(--flip-start, 0deg)) rotateZ(0deg); }
    10%  { transform: translateY(calc(var(--toss-apex, -88px) * 0.375)) scale(0.963) rotateX(var(--fr1, 200deg)) rotateZ(calc(var(--toss-tilt, 0deg) * 0.375)); }
    20%  { transform: translateY(calc(var(--toss-apex, -88px) * 0.700)) scale(0.930) rotateX(var(--fr2, 400deg)) rotateZ(calc(var(--toss-tilt, 0deg) * 0.700)); }
    30%  { transform: translateY(calc(var(--toss-apex, -88px) * 0.909)) scale(0.909) rotateX(var(--fr3, 600deg)) rotateZ(calc(var(--toss-tilt, 0deg) * 0.909)); }
    40%  { transform: translateY(calc(var(--toss-apex, -88px) * 0.999)) scale(0.900) rotateX(var(--fr4, 800deg)) rotateZ(var(--toss-tilt, 0deg)); }
    50%  { transform: translateY(calc(var(--toss-apex, -88px) * 0.959)) scale(0.904) rotateX(var(--fr5, 1000deg)) rotateZ(calc(var(--toss-tilt, 0deg) * 0.959)); }
    60%  { transform: translateY(calc(var(--toss-apex, -88px) * 0.756)) scale(0.924) rotateX(var(--fr6, 1200deg)) rotateZ(calc(var(--toss-tilt, 0deg) * 0.756)); }
    70%  { transform: translateY(calc(var(--toss-apex, -88px) * 0.445)) scale(0.956) rotateX(var(--fr7, 1400deg)) rotateZ(calc(var(--toss-tilt, 0deg) * 0.445)); }
    82%  { transform: translateY(0) scale(1) rotateX(var(--flip-end, 1800deg)) rotateZ(0deg); }
    88%  { transform: translateY(-20px) scale(1) rotateX(var(--flip-end, 1800deg)) rotateZ(0deg); }
    94%  { transform: translateY(0) scale(1) rotateX(var(--flip-end, 1800deg)) rotateZ(0deg); }
    97%  { transform: translateY(-6px) scale(1) rotateX(var(--flip-end, 1800deg)) rotateZ(0deg); }
    100% { transform: translateY(0) scale(1) rotateX(var(--flip-end, 1800deg)) rotateZ(0deg); }
}

/* Shadow shrinks/lightens as the coin rises, snaps back on each bounce. */
@keyframes coinTossShadow {
    0%   { transform: translateX(-50%) scale(1);    opacity: 0.85; }
    45%  { transform: translateX(-50%) scale(0.55); opacity: 0.4; }
    80%  { transform: translateX(-50%) scale(1);    opacity: 0.85; }
    88%  { transform: translateX(-50%) scale(0.8);  opacity: 0.6; }
    100% { transform: translateX(-50%) scale(1);    opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
    .coin.flipping { animation-duration: 0.01s; }
    .coin-container.tossing .coin-shadow { animation: none; }
}

/* Center Spin Button */
#centerSpinBtn {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.spin-center-btn {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(145deg, #667eea, #764ba2);
    border: 3px solid white;
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    z-index: 1;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spin-center-btn:hover {
    transform: translateX(-50%) scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.spin-center-btn:active {
    transform: translateX(-50%) scale(0.95);
}

.spin-center-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: translateX(-50%) scale(1);
}

/* Result Display */
.result-display {
    animation: fadeInUp 0.5s ease;
    margin-top: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 15px;
    border: 2px solid var(--primary-color);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Simple Input Section - Hide for Coin Toss */
#simpleInput {
    display: block;
}

/* Coin Toss Specific Simple Input */
.coin-toss-simple-input {
    max-width: 100%;
}

.coin-toss-simple-input .form-label {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.coin-toss-simple-input .row {
    margin-bottom: 1rem;
}

.coin-toss-simple-input .form-control {
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    padding: 0.75rem;
    transition: all 0.3s ease;
    text-align: center;
    font-weight: 600;
}

.coin-toss-simple-input .form-control:focus {
    border-color: #ffc107;
    box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.25);
}

/* Preset Buttons */
.preset-btn {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.preset-btn:hover {
    border-color: #ffc107;
    background: #fff8e1;
    transform: translateY(-2px);
}

/* Button States */
#mainSpinBtn:disabled,
#centerSpinBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Responsive Design */
@media (max-width: 768px) {
    .coin-container {
        height: 300px;
        max-width: 300px;
    }

    .coin {
        width: 200px;
        height: 200px;
    }

    .coin-side {
        font-size: 1.5rem;
        border: 4px solid #ffc107;
    }

    .coin-inner {
        padding: 15px;
    }

    .spin-center-btn {
        width: 60px;
        height: 60px;
        font-size: 0.75rem;
    }

    .coin-emoji {
        font-size: 3rem;
    }

    .coin-emoji-image {
        width: 100px;
        height: 100px;
    }

    .coin-label {
        font-size: 1.5rem;
    }
}

@media (max-width: 576px) {
    .coin-container {
        height: 250px;
        max-width: 250px;
    }

    .coin {
        width: 180px;
        height: 180px;
    }

    .coin-side {
        font-size: 1.2rem;
        border: 3px solid #ffc107;
    }

    .coin-inner {
        padding: 10px;
    }

    .spin-center-btn {
        width: 50px;
        height: 50px;
        font-size: 0.7rem;
    }

    .coin-emoji {
        font-size: 2.5rem;
    }

    .coin-emoji-image {
        width: 80px;
        height: 80px;
    }

    .coin-label {
        font-size: 1.2rem;
    }
}

/* Winner Modal Styling */
#winnerModal .modal-content {
    border-radius: 15px;
}

#winnerModal .modal-body {
    padding: 3rem 2rem;
}

#winnerModal h2 {
    font-size: 3rem;
}

#winnerModal h3 {
    color: #ffc107;
    font-weight: bold;
}

#winnerModal .display-5 {
    color: #333;
}

/* History & Leaderboard */
.history-item,
.leaderboard-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
}

.history-item:hover,
.leaderboard-item:hover {
    background: #f5f5f5;
}

.history-item:last-child,
.leaderboard-item:last-child {
    border-bottom: none;
}

.history-item-left,
.leaderboard-item-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.history-spin-number,
.leaderboard-rank {
    font-weight: bold;
    color: #666;
    font-size: 0.85rem;
}

.history-winner-name,
.leaderboard-name {
    font-weight: 600;
    color: #333;
}

.history-timestamp,
.leaderboard-count {
    font-size: 0.85rem;
    color: #999;
}

.leaderboard-item.rank-1 {
    background: linear-gradient(135deg, #fff9c4 0%, #fff59d 100%);
}

.leaderboard-item.rank-2 {
    background: linear-gradient(135deg, #e0e0e0 0%, #bdbdbd 100%);
}

.leaderboard-item.rank-3 {
    background: linear-gradient(135deg, #ffccbc 0%, #ffab91 100%);
}

/* Winners Scroll Container */
.winners-scroll-container {
    max-height: 300px;
    overflow-y: auto;
}

.winners-scroll-container::-webkit-scrollbar {
    width: 6px;
}

.winners-scroll-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.winners-scroll-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.winners-scroll-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}