/* Cryptography Games module — matches glassmorphism + emerald accent base theme. */

/* ---------- Game cards ---------- */
.game-card {
    transition: transform .3s ease, border-color .3s ease, box-shadow .3s ease;
    position: relative;
}
.game-card::after {
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 3px;
    background: linear-gradient(90deg,
        rgba(22, 163, 74, 0) 0%,
        rgba(22, 163, 74, 0.7) 40%,
        rgba(34, 197, 94, 0.7) 60%,
        rgba(22, 163, 74, 0) 100%);
    opacity: 0;
    transition: opacity .3s ease;
}
.game-card:hover { transform: translateY(-4px); }
.game-card:hover::after { opacity: 1; }
.game-card .card-header {
    background: linear-gradient(90deg,
        rgba(22, 163, 74, 0.10),
        rgba(22, 163, 74, 0.02),
        transparent);
}
.game-card .btn-diff-select {
    padding: 0.45rem 0.7rem !important;
    font-size: 0.82rem;
}
.game-card .btn-diff-select.active {
    background: linear-gradient(180deg, #22c55e, #15803d) !important;
    color: #fff !important;
    border-color: rgba(22, 163, 74, 0.7) !important;
    box-shadow: 0 4px 14px rgba(22, 163, 74, 0.25);
}
.game-best.empty { color: rgba(148, 163, 184, 0.55) !important; }

/* ---------- Runner modal ---------- */
#gameRunnerModal {
    z-index: 99980 !important;
}
#gameRunnerModal .modal-dialog {
    z-index: 99985 !important;
}
#__games_modal_backdrop,
.__games_modal_backdrop_custom,
.modal-backdrop {
    z-index: 99970 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
}
body.modal-open #gameRunnerModal,
body.modal-open #gameRunnerModal .modal-dialog,
body.modal-open #gameRunnerModal .modal-content,
body.modal-open #gameRunnerModal .modal-header,
body.modal-open #gameRunnerModal .modal-body,
body.modal-open #gameRunnerModal .modal-footer,
body.modal-open #gameRunnerModal .modal-dialog * {
    pointer-events: auto !important;
}
#gameRunnerModal .modal-content {
    border-radius: var(--r-lg, 14px);
    box-shadow: 0 20px 80px rgba(0, 0, 0, 0.6);
}
#gameRunnerModal .modal-header,
#gameRunnerModal .modal-footer {
    background: linear-gradient(180deg,
        rgba(15, 20, 29, 0.98),
        rgba(11, 15, 22, 0.98));
}
#gameRunnerModal .modal-body {
    padding-top: 1.5rem;
    padding-bottom: 1rem;
}

/* Progress pipeline (challenge stages) */
.progress-pipeline {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 0;
    gap: 0.35rem;
    counter-reset: stage;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.progress-pipeline .stage {
    flex: 1 1 0;
    min-width: 130px;
    position: relative;
    padding: 0.7rem 0.85rem;
    border-radius: var(--r-md, 10px);
    background: rgba(11, 15, 22, 0.6);
    border: 1px solid rgba(226, 232, 240, 0.08);
    color: rgba(226, 232, 240, 0.55);
    font-family: var(--font-mono);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    transition: all .25s ease;
}
.progress-pipeline .stage span {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(15, 20, 29, 0.9);
    border: 1px solid rgba(226, 232, 240, 0.10);
    color: rgba(148, 163, 184, 0.85);
    font-size: 0.8rem;
}
.progress-pipeline .stage.active {
    color: var(--text-0);
    border-color: rgba(22, 163, 74, 0.55);
    background: linear-gradient(135deg,
        rgba(22, 163, 74, 0.16),
        rgba(11, 15, 22, 0.88));
    box-shadow: 0 0 0 1px rgba(22, 163, 74, 0.35) inset,
                0 4px 16px rgba(22, 163, 74, 0.15);
}
.progress-pipeline .stage.active span {
    background: linear-gradient(180deg, #22c55e, #15803d);
    border-color: rgba(22, 163, 74, 0.7);
    color: #fff;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.22);
}
.progress-pipeline .stage.done {
    color: rgba(148, 163, 184, 0.9);
    border-color: rgba(148, 163, 184, 0.25);
}
.progress-pipeline .stage.done span {
    background: rgba(22, 163, 74, 0.2);
    border-color: rgba(22, 163, 74, 0.4);
    color: #86efac;
}

/* ---------- Runner: answer slot ---------- */
.answer-mcq {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.answer-mcq .btn {
    justify-content: flex-start;
    text-align: left;
    padding: 0.85rem 1rem !important;
    font-size: 0.95rem;
}
.answer-mcq .btn.correct {
    background: linear-gradient(180deg, #22c55e, #15803d) !important;
    color: #fff !important;
    border-color: rgba(22, 163, 74, 0.8) !important;
    box-shadow: 0 6px 18px rgba(22, 163, 74, 0.25);
}
.answer-mcq .btn.incorrect {
    background: linear-gradient(180deg, #ef4444, #b91c1c) !important;
    color: #fff !important;
    border-color: rgba(220, 38, 38, 0.8) !important;
    box-shadow: 0 6px 18px rgba(220, 38, 38, 0.25);
}

.attempts-log {
    max-height: 200px;
    overflow-y: auto;
    background: rgba(7, 9, 13, 0.6);
    border: 1px solid var(--br-2, rgba(226, 232, 240, 0.1));
    border-radius: var(--r-md, 10px);
    padding: 0.75rem 1rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: #e2e8f0;
}
.attempts-log .attempt-line {
    padding: 2px 0;
    border-bottom: 1px dashed rgba(226, 232, 240, 0.06);
}
.attempts-log .attempt-line:last-child { border-bottom: none; }
.attempt-match-pos { color: #4ade80; font-weight: 700; }
.attempt-match-no  { color: #f87171; font-weight: 700; }

/* ---------- Result card ---------- */
#runnerResultCard.success { border-color: rgba(22, 163, 74, 0.55) !important; }
#runnerResultCard.failure { border-color: rgba(220, 38, 38, 0.55) !important; }
#runnerResultCard.success #runnerResultHeader {
    background: linear-gradient(90deg, rgba(22, 163, 74, 0.22), rgba(22, 163, 74, 0.04)) !important;
    border-bottom: 1px solid rgba(22, 163, 74, 0.55) !important;
    color: #bbf7d0 !important;
}
#runnerResultCard.failure #runnerResultHeader {
    background: linear-gradient(90deg, rgba(220, 38, 38, 0.22), rgba(220, 38, 38, 0.04)) !important;
    border-bottom: 1px solid rgba(220, 38, 38, 0.55) !important;
    color: #fecaca !important;
}

/* ---------- Responsive tweaks for games ---------- */
@media (max-width: 768px) {
    #gameRunnerModal .modal-dialog { margin: 0.5rem; max-width: none; }
    #gameRunnerModal .modal-content { min-height: calc(100vh - 1rem); }
    .progress-pipeline .stage { min-width: 120px; font-size: 0.72rem; padding: 0.5rem 0.6rem; }
    .progress-pipeline .stage span { width: 24px; height: 24px; font-size: 0.7rem; }
    #gameRunnerModal .modal-header { flex-wrap: wrap; gap: 0.5rem; }
    #gameRunnerModal .modal-header > div.me-3 { margin-right: 0 !important; width: 100%; order: 3; display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: space-between; }
    .game-card .card-body { padding: 0.9rem; }
}

/* Animations */
@keyframes xpPop {
    0%   { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-40px) scale(1.3); opacity: 0; }
}
.xp-pop {
    position: absolute;
    pointer-events: none;
    color: #4ade80;
    font-family: var(--font-mono);
    font-weight: 800;
    animation: xpPop 1.1s ease-out forwards;
    z-index: 50;
    font-size: 1.1rem;
}

/* ===========================================================
   CRAZY MODE SPECIAL CARD HIGHLIGHT — STAND OUT VISUALLY
   =========================================================== */
@keyframes crazyCardPulse {
    0%, 100% {
        box-shadow: 0 0 0 rgba(220, 38, 38, 0.0),
                    0 10px 40px rgba(0,0,0,0.5),
                    inset 0 1px 0 rgba(255,255,255,0.03);
        border-color: rgba(220, 38, 38, 0.55);
        transform: translateY(0);
        filter: brightness(1) contrast(1);
    }
    25% {
        border-color: rgba(249, 115, 22, 0.95);
        filter: brightness(1.05) contrast(1.02);
    }
    50% {
        box-shadow: 0 0 55px rgba(220, 38, 38, 0.85),
                    0 0 140px rgba(239, 68, 68, 0.55),
                    0 0 220px rgba(248, 113, 113, 0.25),
                    0 18px 80px rgba(0,0,0,0.7);
        border-color: rgba(255, 56, 56, 1);
        transform: translateY(-3px);
        filter: brightness(1.1) contrast(1.05) saturate(1.15);
    }
    75% {
        border-color: rgba(185, 28, 28, 0.9);
    }
}
@keyframes crazyCardShake {
    0%, 100% { transform: translateX(0) translateY(0) rotate(0); }
    10%      { transform: translateX(-2px) translateY(-1px) rotate(-0.3deg); }
    20%      { transform: translateX(2px)  translateY(-3px) rotate(0.4deg); }
    30%      { transform: translateX(-2px) translateY(0px)  rotate(-0.2deg); }
    40%      { transform: translateX(3px)  translateY(-2px) rotate(0.5deg); }
    50%      { transform: translateX(-1px) translateY(-4px) rotate(-0.4deg); }
    60%      { transform: translateX(2px)  translateY(-1px) rotate(0.2deg); }
    70%      { transform: translateX(-3px) translateY(-3px) rotate(-0.3deg); }
    80%      { transform: translateX(1px)  translateY(-2px) rotate(0.3deg); }
    90%      { transform: translateX(-2px) translateY(0px)  rotate(-0.1deg); }
}
.game-card-color-danger {
    border-color: rgba(220, 38, 38, 0.85) !important;
    animation: crazyCardPulse 2.0s ease-in-out infinite,
               crazyCardShake 5.8s ease-in-out infinite;
    background:
        radial-gradient(circle at 8% 8%, rgba(220,38,38,0.22), transparent 45%),
        radial-gradient(circle at 92% 92%, rgba(249,115,22,0.20), transparent 45%),
        radial-gradient(circle at 50% 0%, rgba(185, 28, 28, 0.12), transparent 55%),
        linear-gradient(180deg, rgba(15,20,29,0.98), rgba(8, 12, 18, 0.99)) !important;
    position: relative;
    overflow: hidden;
}
.game-card-color-danger::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(
            115deg,
            transparent 0px, transparent 10px,
            rgba(220,38,38,0.05) 10px,
            rgba(220,38,38,0.05) 11px
        );
    pointer-events: none;
    z-index: 1;
}
.game-card-color-danger::after {
    content: "☠️ DANGER";
    position: absolute;
    top: 16px;
    right: -52px;
    background: linear-gradient(90deg, #7f1d1d, #dc2626 50%, #f97316);
    color: #fff;
    font-family: var(--font-mono);
    font-weight: 900;
    font-size: 0.7rem;
    letter-spacing: 2px;
    padding: 4px 56px;
    transform: rotate(40deg);
    box-shadow: 0 3px 14px rgba(220,38,38,0.8),
                0 0 30px rgba(248, 113, 113, 0.35),
                inset 0 1px 0 rgba(255,255,255,0.25);
    z-index: 3;
    pointer-events: none;
    opacity: 1;
    text-transform: uppercase;
}
.game-card-color-danger .card-header {
    background: linear-gradient(90deg,
        rgba(220, 38, 38, 0.25),
        rgba(239, 68, 68, 0.08),
        transparent) !important;
    border-color: rgba(220, 38, 38, 0.4) !important;
    position: relative;
    z-index: 2;
}
.game-card-color-danger > * {
    position: relative;
    z-index: 2;
}
.game-card-color-danger .btn-play-game {
    background: linear-gradient(180deg, #ef4444 0%, #b91c1c 60%, #7f1d1d 100%) !important;
    border-color: rgba(248, 113, 113, 1) !important;
    box-shadow: 0 6px 26px rgba(220, 38, 38, 0.65),
                0 0 35px rgba(239, 68, 68, 0.35),
                inset 0 1px 0 rgba(255,255,255,0.18),
                inset 0 -2px 0 rgba(0,0,0,0.3);
    font-weight: 800;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}
.game-card-color-danger .btn-play-game::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.14) 50%,
        transparent 100%
    );
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}
.game-card-color-danger .btn-play-game:hover::before {
    transform: translateX(100%);
}
.game-card-color-danger .btn-play-game:hover {
    filter: brightness(1.12) saturate(1.15);
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 8px 35px rgba(220, 38, 38, 0.8),
                0 0 55px rgba(239, 68, 68, 0.5),
                inset 0 1px 0 rgba(255,255,255,0.2);
}
.game-card-color-danger .btn-diff-select.active {
    background: linear-gradient(180deg, #ef4444, #b91c1c) !important;
    color: #fff !important;
    border-color: rgba(220, 38, 38, 0.8) !important;
    box-shadow: 0 4px 18px rgba(220, 38, 38, 0.45) !important;
}

/* ===========================================================
   INFO BUTTONS / BRANDING — NO HOVER UNDERLINE (per spec)
   =========================================================== */
.card-header button[onclick*="openHowToPlay"],
.btn-sm.btn-outline-info[onclick*="openHowToPlay"],
.brand-button,
.encryptsys-brand a,
a.encryptsys-brand {
    text-decoration: none !important;
}
.card-header button[onclick*="openHowToPlay"]:hover,
.btn-sm.btn-outline-info[onclick*="openHowToPlay"]:hover {
    text-decoration: none !important;
}
button[title="How to play"]:hover,
button[title="How to play · rules & worked example"]:hover {
    text-decoration: none !important;
}

/* ===========================================================
   LEADERBOARD TABLE STYLING
   =========================================================== */
.table-responsive table tbody tr {
    transition: background-color 0.2s ease, transform 0.15s ease;
}
.table-responsive table tbody tr:hover {
    background-color: rgba(34, 197, 94, 0.06) !important;
}
.table-responsive table tbody tr.table-warning:hover {
    background-color: rgba(234, 179, 8, 0.14) !important;
}
.table-responsive th,
.table-responsive td {
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}
.leaderboard-row-top1 {
    background: linear-gradient(90deg, rgba(234, 179, 8, 0.15), transparent 70%) !important;
}
.leaderboard-row-top2 {
    background: linear-gradient(90deg, rgba(148, 163, 184, 0.12), transparent 70%) !important;
}
.leaderboard-row-top3 {
    background: linear-gradient(90deg, rgba(180, 83, 9, 0.12), transparent 70%) !important;
}

/* Crazy runner challenge area: scanline-danger aesthetic */
#gameRunnerModal .bg-gradient-red {
    background: linear-gradient(135deg, rgba(127,29,29,0.40) 0%, rgba(185,28,28,0.30) 50%, rgba(15,23,42,0.95) 100%) !important;
    border: 2px solid rgba(248, 113, 113, 0.6) !important;
    box-shadow: 0 0 40px rgba(220, 38, 38, 0.45),
                inset 0 1px 0 rgba(255,255,255,0.06);
    position: relative;
    overflow: hidden;
}
#gameRunnerModal .bg-gradient-red::before {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(220, 38, 38, 0.08) 0px,
        rgba(220, 38, 38, 0.08) 1px,
        transparent 1px,
        transparent 4px
    );
    pointer-events: none;
    opacity: 0.4;
}
.font-lg-1 {
    font-size: 1.08rem !important;
    line-height: 1.55 !important;
}