/* Public MiniGame runtime shell.
   Keep the game canvas wide while preserving readable text and safe mobile gutters. */
.game-runtime-shell {
    width: 100%;
    max-width: none;
    margin-inline: auto;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.game-runtime-header,
.game-runtime-board {
    border: 0 !important;
    box-shadow: 0 1rem 2.5rem rgba(15, 23, 42, .08) !important;
}

.game-runtime-header {
    padding: clamp(1.25rem, 2.5vw, 2.25rem) !important;
    border-radius: 1.25rem !important;
}

.game-runtime-header h1 {
    font-size: clamp(1.45rem, 2.25vw, 2.35rem);
    letter-spacing: -.035em;
    line-height: 1.15 !important;
}

.game-runtime-header p {
    max-width: 72ch;
    color: rgba(255, 255, 255, .78) !important;
}

.game-runtime-xp {
    flex: 0 0 auto;
    min-width: 7.5rem;
    text-align: center;
    border-radius: .9rem !important;
}

.game-runtime-board {
    border-radius: 1.5rem !important;
    padding: clamp(1.25rem, 3vw, 3rem) !important;
    background: var(--game-surface, #f8fafc) !important;
}

.game-runtime-instruction {
    max-width: 70ch;
    margin-inline: auto;
    font-size: clamp(1rem, 1.6vw, 1.35rem);
    line-height: 1.45 !important;
}

.game-runtime-actions {
    display: flex;
    justify-content: center;
    margin-top: clamp(1.5rem, 3vw, 2.75rem);
}

.game-runtime-check {
    min-width: 14rem;
    border-radius: 999px !important;
    font-weight: 800 !important;
    letter-spacing: .01em;
}

.game-runtime-check:focus-visible,
.game-result-modal .btn:focus-visible,
.game-result-modal .btn-close:focus-visible {
    outline: 3px solid rgba(96, 165, 250, .65);
    outline-offset: 3px;
}

.sortable-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 76rem;
    min-height: 12rem;
    margin-inline: auto;
}

.code-block {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 1.15rem 3.5rem 1.15rem 1.35rem;
    border-radius: .85rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: clamp(.95rem, 1.5vw, 1.15rem);
    line-height: 1.45;
    cursor: grab;
    border: 1px solid rgba(148, 163, 184, .14);
    box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .12);
    transition: transform .2s, border-color .2s, box-shadow .2s;
    user-select: none;
    position: relative;
    overflow-wrap: anywhere;
}

.code-block:hover,
.code-block:focus-visible {
    transform: translateX(.2rem);
    border-color: rgba(230, 126, 34, .7);
    box-shadow: 0 .4rem 1rem rgba(0, 0, 0, .18);
}

.code-block.dragging {
    opacity: .5;
    transform: scale(.98);
}

.code-block::before {
    content: '\f0c9';
    font-family: FontAwesome;
    position: absolute;
    right: 1.25rem;
    color: #94a3b8;
    opacity: .55;
}

.ghost {
    background: rgba(148, 163, 184, .12);
    border: 1px dashed rgba(148, 163, 184, .5);
    color: transparent;
}

[data-bs-theme='dark'] .code-block {
    background: #111827;
    color: #e5e7eb;
}

.matching-grid {
    position: relative;
    isolation: isolate;
    width: 100%;
    max-width: 80rem;
    margin-inline: auto;
    align-items: stretch;
}

.matching-grid > #left-side,
.matching-grid > #right-side,
.matching-grid > [data-role='left-side'],
.matching-grid > [data-role='right-side'] {
    position: relative;
    z-index: 1;
}

.matching-connectors {
    position: absolute;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.matching-connector {
    fill: none;
    stroke: rgba(124, 58, 237, .62);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-dasharray: 5 7;
    opacity: .78;
    transition: stroke .2s ease, opacity .2s ease, stroke-width .2s ease;
}

.matching-connector.is-correct {
    stroke: rgba(16, 185, 129, .8);
    stroke-dasharray: none;
}

.matching-connector.is-incorrect {
    stroke: rgba(239, 68, 68, .78);
    stroke-dasharray: 2 6;
}

[data-bs-theme='dark'] .matching-connector {
    stroke: rgba(196, 181, 253, .72);
}

[data-bs-theme='dark'] .matching-connector.is-correct {
    stroke: rgba(110, 231, 183, .82);
}

[data-bs-theme='dark'] .matching-connector.is-incorrect {
    stroke: rgba(252, 165, 165, .82);
}

.memory-grid {
    display: grid;
    width: 100%;
    max-width: 72rem;
    margin-inline: auto;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}

.memory-card {
    height: clamp(8rem, 16vw, 10rem);
    position: relative;
    perspective: 1000px;
    cursor: pointer;
}

.memory-card .card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform .6s;
    transform-style: preserve-3d;
    box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .12);
    border-radius: .9rem;
}

.memory-card.flipped .card-inner {
    transform: rotateY(180deg);
    box-shadow: 0 .35rem 1rem rgba(20, 184, 166, .22);
}

.memory-card .card-front,
.memory-card .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: .9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.memory-card .card-front {
    background: linear-gradient(135deg, #1abc9c, #16a085);
    color: white;
}

.memory-card .card-back {
    background: white;
    color: #1e293b;
    transform: rotateY(180deg);
    border: 0;
    font-weight: 700;
    font-size: 1.05rem;
    padding: .65rem;
    overflow-wrap: anywhere;
}

.memory-card.matched {
    cursor: default;
}

.memory-card.matched .card-inner {
    box-shadow: 0 .35rem 1rem rgba(16, 185, 129, .18);
}

[data-bs-theme='dark'] .memory-card .card-back {
    background: #0f172a;
    color: #e2e8f0;
}

.game-result-modal {
    z-index: 1060;
}

.game-result-modal .modal-dialog {
    width: min(100% - 2rem, 42rem);
    max-width: none !important;
    margin: 1rem auto;
}

.game-result-modal .modal-content {
    overflow: hidden;
    border: 0;
    border-radius: 1.35rem;
    box-shadow: 0 1.5rem 4rem rgba(2, 6, 23, .35);
}

.game-result-modal .modal-header {
    position: relative;
    padding: clamp(1.5rem, 4vw, 2.75rem) !important;
}

.game-result-modal .game-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
    opacity: .9;
    filter: brightness(0) invert(1);
}

.game-result-modal .game-result-icon {
    font-size: clamp(3rem, 7vw, 5rem);
    margin-bottom: 1rem;
}

.game-result-modal .game-result-title {
    margin: 0;
    font-size: clamp(1.65rem, 4vw, 2.5rem);
    line-height: 1.1 !important;
}

.game-result-modal .modal-body {
    padding: clamp(1.25rem, 4vw, 2.5rem) !important;
}

.game-result-modal .game-result-message {
    margin-bottom: 2rem;
    color: #475569;
    font-size: clamp(1rem, 2vw, 1.25rem);
    font-weight: 500;
    line-height: 1.6 !important;
}

.game-result-actions {
    display: flex;
    gap: .75rem;
}

.game-result-actions .btn {
    min-height: 3.25rem;
    border-radius: .85rem !important;
    font-weight: 750 !important;
}

.memory-feedback {
    min-height: 3rem;
    margin: 0 auto 1.25rem;
    padding: .75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    border: 1px solid rgba(20, 184, 166, .24);
    border-radius: .75rem;
    background: rgba(20, 184, 166, .08);
    color: #0f766e;
    font-weight: 700;
    text-align: center;
}

.memory-feedback[data-state='success'] {
    border-color: rgba(16, 185, 129, .5);
    background: rgba(16, 185, 129, .1);
    color: #047857;
}

.memory-feedback[data-state='failure'] {
    border-color: rgba(245, 158, 11, .5);
    background: rgba(245, 158, 11, .1);
    color: #92400e;
}

[data-bs-theme='dark'] .memory-feedback { color: #99f6e4; }
[data-bs-theme='dark'] .memory-feedback[data-state='success'] { color: #a7f3d0; }
[data-bs-theme='dark'] .memory-feedback[data-state='failure'] { color: #fde68a; }

.matching-item {
    min-height: 5rem;
    padding: 1.1rem;
    background: #ffffff;
    border: 1px solid rgba(148, 163, 184, .22);
    border-radius: .9rem;
    cursor: pointer;
    transition: transform .2s, border-color .2s, background .2s, box-shadow .2s;
    font-size: clamp(.95rem, 1.6vw, 1.1rem);
    font-weight: 700;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.matching-item:hover,
.matching-item:focus-visible {
    border-color: #a855f7;
    background: #faf5ff;
    transform: translateY(-2px);
}

.matching-item.selected {
    background: #7c3aed !important;
    border-color: rgba(196, 181, 253, .9) !important;
    color: #ffffff !important;
    box-shadow: 0 .35rem 1rem rgba(124, 58, 237, .22);
    transform: translateY(-2px) scale(1.01);
}

.matching-item.match-correct {
    background: #047857 !important;
    border-color: rgba(110, 231, 183, .9) !important;
    color: #ffffff !important;
    box-shadow: 0 .35rem 1rem rgba(16, 185, 129, .2);
    cursor: default;
    opacity: 1 !important;
}

.matching-item.match-correct::after {
    content: '✓ ĐÚNG';
    position: absolute;
    top: .45rem;
    right: .65rem;
    font-size: .68rem;
    letter-spacing: .04em;
    font-weight: 800;
}

.matching-item.match-incorrect {
    background: #b91c1c !important;
    border-color: rgba(252, 165, 165, .9) !important;
    color: #ffffff !important;
    box-shadow: 0 .35rem 1rem rgba(239, 68, 68, .2);
    animation: matching-shake .35s ease-in-out;
}

.matching-item.match-incorrect::after {
    content: '✕ CHƯA ĐÚNG';
    position: absolute;
    top: .45rem;
    right: .65rem;
    font-size: .68rem;
    letter-spacing: .04em;
    font-weight: 800;
}

.matching-item.pending {
    background: rgba(124, 58, 237, .12) !important;
    border-color: rgba(167, 139, 250, .78) !important;
    color: #6d28d9 !important;
    box-shadow: 0 .25rem .75rem rgba(124, 58, 237, .14);
}

.matching-item.pending::after {
    content: 'ĐÃ CHỌN';
    position: absolute;
    top: .45rem;
    right: .65rem;
    font-size: .68rem;
    letter-spacing: .04em;
    font-weight: 800;
}

.matching-item.match-missing {
    background: rgba(245, 158, 11, .14) !important;
    border-color: rgba(251, 191, 36, .78) !important;
    color: #92400e !important;
}

.matching-item.match-missing::after {
    content: 'CHƯA CHỌN';
    position: absolute;
    top: .45rem;
    right: .65rem;
    font-size: .68rem;
    letter-spacing: .04em;
    font-weight: 800;
}

.matching-item.matched {
    background: #047857 !important;
    border-color: rgba(110, 231, 183, .9) !important;
    color: #ffffff !important;
    cursor: default;
    opacity: 1 !important;
}

.matching-feedback {
    min-height: 3.25rem;
    margin: 0 auto 1.25rem;
    border: 1px solid transparent;
    border-radius: .85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    padding: .75rem 1rem;
    text-align: center;
    font-weight: 700;
}

.matching-feedback[data-state='idle'] {
    background: rgba(148, 163, 184, .12);
    border-color: rgba(148, 163, 184, .28);
    color: #64748b;
}

.matching-feedback[data-state='selected'] {
    background: rgba(124, 58, 237, .12);
    border-color: rgba(167, 139, 250, .6);
    color: #6d28d9;
}

.matching-feedback[data-state='correct'] {
    background: rgba(16, 185, 129, .14);
    border-color: rgba(52, 211, 153, .7);
    color: #047857;
}

.matching-feedback[data-state='incorrect'] {
    background: rgba(239, 68, 68, .14);
    border-color: rgba(248, 113, 113, .7);
    color: #b91c1c;
}

.matching-progress {
    display: block;
    margin: 0 auto 1.5rem;
    color: #64748b;
    font-size: .9rem;
    font-weight: 700;
    text-align: center;
}

@media (max-width: 767.98px) {
    .matching-connectors { display: none; }
    .matching-grid { grid-template-columns: 1fr !important; }
}

@keyframes matching-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-.35rem); }
    75% { transform: translateX(.35rem); }
}

[data-bs-theme='dark'] .matching-item {
    background: #0f172a;
    border-color: #475569;
    color: #e2e8f0;
}

[data-bs-theme='dark'] .matching-item:hover,
[data-bs-theme='dark'] .matching-item:focus-visible {
    background: #312e4f;
}

[data-bs-theme='dark'] .matching-feedback[data-state='idle'],
[data-bs-theme='dark'] .matching-progress {
    color: #cbd5e1;
}

[data-bs-theme='dark'] .matching-feedback[data-state='selected'] { color: #ddd6fe; }
[data-bs-theme='dark'] .matching-feedback[data-state='correct'] { color: #a7f3d0; }
[data-bs-theme='dark'] .matching-feedback[data-state='incorrect'] { color: #fecaca; }
[data-bs-theme='dark'] .matching-item.pending { color: #ddd6fe !important; }
[data-bs-theme='dark'] .matching-item.match-missing { color: #fde68a !important; }

[data-bs-theme='dark'] .game-runtime-board {
    --game-surface: #1e293b;
}

[data-bs-theme='dark'] .game-result-modal .modal-content {
    background: #0f172a;
}

[data-bs-theme='dark'] .game-result-modal .game-result-message {
    color: #cbd5e1;
}

@media (max-width: 991.98px) {
    .memory-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
}

@media (max-width: 767.98px) {
    .game-runtime-header .d-flex {
        align-items: flex-start !important;
        flex-direction: column;
        gap: 1rem;
    }

    .game-runtime-xp {
        min-width: 0;
        width: 100%;
    }

    .game-runtime-actions,
    .game-result-actions {
        flex-direction: column;
    }

    .game-runtime-check,
    .game-result-actions .btn {
        width: 100%;
    }

    .game-result-modal .modal-dialog {
        width: min(100% - 1rem, 42rem);
        margin: .5rem auto;
    }
}

/* Lesson-owned embedded MiniGame surface. */
.lesson-minigame-runtime {
    width: 100%;
    min-width: 0;
}

.lesson-minigame-runtime .game-runtime-header,
.lesson-minigame-runtime .game-runtime-board {
    box-shadow: 0 .75rem 1.75rem rgba(15, 23, 42, .08) !important;
}

.lesson-minigame-runtime .game-runtime-header {
    padding: clamp(1rem, 2vw, 1.5rem) !important;
    border-radius: 1rem !important;
}

.lesson-minigame-runtime .game-runtime-header h2 {
    font-size: clamp(1.25rem, 2vw, 1.75rem);
    line-height: 1.2 !important;
    letter-spacing: -.02em;
}

.lesson-minigame-runtime .sortable-list {
    gap: clamp(1rem, 1.8vw, 1.35rem);
}

.lesson-minigame-runtime .game-runtime-board {
    padding: clamp(1rem, 2.5vw, 2rem) !important;
    border-radius: 1.15rem !important;
}

.lesson-minigame-result-feedback {
    margin-top: 1rem;
    padding: .8rem 1rem;
    border: 1px solid transparent;
    border-radius: .75rem;
    font-weight: 700;
    text-align: center;
}

.lesson-minigame-result-feedback.is-success {
    background: rgba(16, 185, 129, .12);
    border-color: rgba(16, 185, 129, .45);
    color: #047857;
}

.lesson-minigame-result-feedback.is-failure {
    background: rgba(239, 68, 68, .1);
    border-color: rgba(239, 68, 68, .4);
    color: #b91c1c;
}

.lesson-minigame-runtime .game-runtime-actions {
    gap: .75rem;
    flex-wrap: wrap;
}

@media (max-width: 767.98px) {
    .lesson-minigame-runtime .game-runtime-header .d-flex {
        align-items: flex-start !important;
        flex-direction: column;
        gap: .75rem;
    }

    .lesson-minigame-runtime .game-runtime-header .badge {
        align-self: flex-start;
    }

    .lesson-minigame-runtime .game-runtime-actions > * {
        width: 100%;
    }
}
