/* =========================================================================
   SECOURSIM — INTERACTIVE PROTOCOL MINIGAMES (WAVES 1 + 2 + 3)
   Tactile Direct Manipulation · CNESST / ILCOR Living Protocol Engine
   ========================================================================= */

.mgx-mode-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 4px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
}

.mgx-mode-btn {
    border: none;
    background: transparent;
    color: #475569;
    font-size: 0.76rem;
    font-weight: 800;
    padding: 7px 13px;
    min-height: 34px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.18s ease;
    font-family: inherit;
}

.mgx-mode-btn.active {
    background: #0f172a;
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
}

.mgx-mode-btn.active.mode-field {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

.mgx-stage {
    width: 100%;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    user-select: none;
    -webkit-user-select: none;
    text-align: left;
}

.mgx-stage.hidden {
    display: none !important;
}

/* Header vitals + protocol breadcrumb */
.mgx-hud {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #0f172a;
    color: #f8fafc;
    border-radius: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.74rem;
}

.mgx-hud-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.mgx-vital-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    font-weight: 700;
    transition: all 0.2s ease;
}

.mgx-vital-pill.ok { color: #4ade80; border-color: rgba(74, 222, 128, 0.4); }
.mgx-vital-pill.warn { color: #fbbf24; border-color: rgba(251, 191, 36, 0.45); }
.mgx-vital-pill.crit { color: #f87171; border-color: rgba(248, 113, 113, 0.55); animation: mgxPulseCrit 1s infinite; }

@keyframes mgxPulseCrit {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
    50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0); }
}

.mgx-stepper {
    display: flex;
    gap: 5px;
    width: 100%;
}

.mgx-step-seg {
    flex: 1;
    height: 6px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
    transition: background 0.25s ease;
}

.mgx-step-seg.done { background: #10b981; }
.mgx-step-seg.active { background: #2563eb; }

/* Main clinical viewport */
.mgx-viewport {
    position: relative;
    width: 100%;
    min-height: 235px;
    border-radius: 16px;
    background: radial-gradient(circle at 50% 35%, #1e293b 0%, #0f172a 100%);
    border: 1px solid #334155;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.mgx-viewport.light-clinical {
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-color: #cbd5e1;
}

.mgx-viewport-badge {
    position: absolute;
    top: 8px;
    left: 10px;
    z-index: 6;
    background: rgba(15, 23, 42, 0.86);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.4);
    padding: 3px 9px;
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.2px;
    pointer-events: none;
}

.mgx-viewport-right-badge {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 6;
    background: rgba(15, 23, 42, 0.86);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 3px 9px;
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    pointer-events: none;
}

/* Status banner */
.mgx-status {
    padding: 10px 12px;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    font-size: 0.88rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.4;
    text-align: center;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mgx-status.ok {
    background: #ecfdf5;
    border-color: #34d399;
    color: #065f46;
}

.mgx-status.warn {
    background: #fffbeb;
    border-color: #fbbf24;
    color: #92400e;
}

.mgx-status.error {
    background: #fef2f2;
    border-color: #f87171;
    color: #991b1b;
    animation: mgxShake 0.34s ease;
}

@keyframes mgxShake {
    0%, 100% { transform: translateX(0); }
    22% { transform: translateX(-6px); }
    45% { transform: translateX(6px); }
    70% { transform: translateX(-4px); }
}

/* CSA Z1220-17 Interactive Tool Tray */
.mgx-tray-wrap {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 8px 10px;
}

.mgx-tray-label {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mgx-tray {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
    gap: 7px;
}

.mgx-tool {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 6px;
    border-radius: 11px;
    border: 1.5px solid #cbd5e1;
    background: #f8fafc;
    color: #0f172a;
    font-size: 0.74rem;
    font-weight: 800;
    text-align: center;
    cursor: grab;
    transition: all 0.16s ease;
    touch-action: none;
    line-height: 1.2;
}

.mgx-tool:hover:not(:disabled) {
    border-color: #3b82f6;
    background: #eff6ff;
    transform: translateY(-1px);
}

.mgx-tool.selected {
    border-color: #2563eb;
    background: #dbeafe;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22);
    color: #1e3a8a;
}

.mgx-tool.used {
    background: #ecfdf5;
    border-color: #34d399;
    color: #065f46;
    opacity: 0.75;
    cursor: default;
}

.mgx-tool-ico {
    font-size: 1.35rem;
    line-height: 1;
    pointer-events: none;
}

/* Neutral clinical action buttons (NO red trap spoiler!) */
.mgx-choices {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
    width: 100%;
}

.mgx-choices.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.mgx-choice-btn {
    width: 100%;
    padding: 10px 12px;
    border-radius: 11px;
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    font-size: 0.84rem;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: all 0.16s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-family: inherit;
}

.mgx-choice-btn:hover:not(:disabled) {
    border-color: #2563eb;
    background: #eff6ff;
}

.mgx-choice-btn.correct {
    border-color: #16a34a;
    background: #dcfce7;
    color: #14532d;
}

.mgx-choice-btn.wrong {
    border-color: #dc2626;
    background: #fee2e2;
    color: #991b1b;
}

/* Progress / gauges */
.mgx-bar-track {
    width: 100%;
    height: 10px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
}

.mgx-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #0284c7, #10b981);
    transition: width 0.15s linear;
}

/* Rotary windlass dial (Tourniquet) */
.mgx-dial-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
}

.mgx-dial {
    position: relative;
    width: 116px;
    height: 116px;
    border-radius: 50%;
    background: radial-gradient(circle, #1e293b 45%, #0f172a 100%);
    border: 4px solid #334155;
    box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.6), 0 6px 18px rgba(15, 23, 42, 0.22);
    touch-action: none;
    cursor: grab;
    flex-shrink: 0;
}

.mgx-dial-rod {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 86px;
    height: 16px;
    margin-left: -43px;
    margin-top: -8px;
    border-radius: 999px;
    background: linear-gradient(90deg, #dc2626 0%, #f97316 50%, #dc2626 100%);
    border: 2px solid #fecaca;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.mgx-dial-knob {
    position: absolute;
    right: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fef08a;
    border: 2px solid #b45309;
}

/* Gesture Canvas (Heimlich J, Powder Brush, Eye Flush, Scissors Cut) */
.mgx-canvas-box {
    position: relative;
    width: 100%;
    height: 235px;
    touch-action: none;
}

.mgx-canvas-box canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* START Triage Scene Grid */
.mgx-triage-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    padding: 10px;
}

.mgx-victim-card {
    position: relative;
    background: rgba(255, 255, 255, 0.08);
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    padding: 10px 8px;
    color: #f8fafc;
    text-align: center;
    cursor: pointer;
    transition: all 0.18s ease;
}

.mgx-victim-card:hover {
    border-color: #38bdf8;
    background: rgba(56, 189, 248, 0.14);
}

.mgx-victim-card.active {
    border-color: #facc15;
    box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.4);
}

.mgx-victim-card.tagged-vert { border-color: #22c55e; background: rgba(34, 197, 94, 0.18); }
.mgx-victim-card.tagged-jaune { border-color: #eab308; background: rgba(234, 179, 8, 0.18); }
.mgx-victim-card.tagged-rouge { border-color: #ef4444; background: rgba(239, 68, 68, 0.22); }
.mgx-victim-card.tagged-noir { border-color: #94a3b8; background: rgba(15, 23, 42, 0.82); }

.mgx-tag-pill {
    display: inline-block;
    margin-top: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.04em;
}

.mgx-tag-btn-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    width: 100%;
}

.mgx-tag-btn {
    padding: 9px 6px;
    border-radius: 10px;
    border: 2px solid transparent;
    font-weight: 900;
    font-size: 0.78rem;
    cursor: pointer;
    transition: transform 0.15s ease;
    font-family: inherit;
}

.mgx-tag-btn:active { transform: scale(0.96); }
.mgx-tag-btn.vert { background: #22c55e; color: #052e16; }
.mgx-tag-btn.jaune { background: #facc15; color: #422006; }
.mgx-tag-btn.rouge { background: #dc2626; color: #ffffff; }
.mgx-tag-btn.noir { background: #1e293b; color: #ffffff; border-color: #475569; }

/* CPR Depth + Recoil Live Meter */
.mgx-cpr-layout {
    display: grid;
    grid-template-columns: 1fr 74px;
    gap: 10px;
    width: 100%;
    padding: 12px;
    align-items: center;
}

.mgx-depth-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.mgx-depth-track {
    position: relative;
    width: 34px;
    height: 165px;
    background: #020617;
    border: 2px solid #475569;
    border-radius: 10px;
    overflow: hidden;
}

.mgx-depth-zone {
    position: absolute;
    left: 0;
    right: 0;
    top: 62.5%; /* 5 cm out of 8 cm */
    height: 12.5%; /* 5-6 cm */
    background: rgba(34, 197, 94, 0.35);
    border-top: 2px solid #22c55e;
    border-bottom: 2px solid #22c55e;
    z-index: 2;
}

.mgx-depth-fill {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0%;
    background: linear-gradient(180deg, #38bdf8, #22c55e);
    transition: height 0.05s linear;
}

/* Ghost drag chip */
.mgx-drag-ghost {
    position: fixed;
    z-index: 200000;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(1.08);
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.92);
    color: #ffffff;
    border: 2px solid #38bdf8;
    font-size: 0.8rem;
    font-weight: 800;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Primary interactive CTA */
.mgx-btn-primary {
    padding: 11px 16px;
    border-radius: 11px;
    border: none;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    font-weight: 800;
    font-size: 0.88rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    font-family: inherit;
    transition: transform 0.14s ease, filter 0.14s ease;
}

.mgx-btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.mgx-btn-primary:active:not(:disabled) { transform: scale(0.98); }
.mgx-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.mgx-btn-secondary {
    padding: 9px 12px;
    border-radius: 10px;
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
}

.mgx-btn-danger {
    padding: 11px 16px;
    border-radius: 11px;
    border: none;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: #ffffff;
    font-weight: 900;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4);
    font-family: inherit;
}

.mgx-inline-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    width: 100%;
}

/* Guided hotspot vs Field mode */
.mgx-hotspot {
    position: absolute;
    border-radius: 50%;
    transition: all 0.2s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mgx-stage.mode-guided .mgx-hotspot.hintable {
    border: 2px dashed rgba(56, 189, 248, 0.85);
    background: rgba(56, 189, 248, 0.18);
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.35);
}

.mgx-stage.mode-field .mgx-hotspot.hintable {
    border: 1px solid transparent;
    background: transparent;
}

.mgx-stage.mode-field .mgx-guided-only {
    display: none !important;
}

@media (max-width: 560px) {
    .mgx-triage-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .mgx-tray {
        grid-template-columns: repeat(3, 1fr);
    }
    .mgx-choices.cols-2 {
        grid-template-columns: 1fr;
    }
    .mgx-viewport {
        min-height: 210px;
    }
}
