/* ============================================================
 * UM Liveness Check - frontend styles
 * Scoped under .um-lc-* to avoid clashing with theme/UM styles.
 * ============================================================ */

:root {
    --um-lc-accent: #d4af37;
    --um-lc-accent-soft: rgba(212, 175, 55, 0.15);
    --um-lc-bg: #ffffff;
    --um-lc-bg-dark: #0c0e12;
    --um-lc-text: #111827;
    --um-lc-muted: #6b7280;
    --um-lc-border: #e5e7eb;
    --um-lc-radius: 16px;
}

/* ============================================================
 * Standalone widget section (renders BEFORE the UM form)
 * ============================================================ */

.um-lc-widget {
    margin: 0 0 22px;
    padding: 18px;
    background: #fff;
    border: 1px solid var(--um-lc-border);
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.um-lc-widget-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.um-lc-card-icon {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--um-lc-accent-soft);
    color: var(--um-lc-accent);
    border-radius: 10px;
}
.um-lc-card-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    line-height: 1.35;
    min-width: 0;
}
.um-lc-card-title {
    font-size: 14.5px;
    font-weight: 600;
    color: var(--um-lc-text);
}
.um-lc-card-desc {
    font-size: 12.5px;
    color: var(--um-lc-muted);
    margin-top: 2px;
}
.um-lc-card-progress {
    flex-shrink: 0;
    padding: 6px 12px;
    background: var(--um-lc-accent-soft);
    border-radius: 999px;
    min-width: 56px;
    text-align: center;
}
.um-lc-card-percent {
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    font-weight: 700;
    color: var(--um-lc-accent);
}

/* Slim track under the header showing overall verification progress */
.um-lc-widget-track {
    width: 100%;
    height: 6px;
    background: var(--um-lc-border);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 14px;
}
.um-lc-widget-fill {
    height: 100%;
    background: var(--um-lc-accent);
    border-radius: 999px;
    transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Verified state */
.um-lc-widget[data-umlc-state="verified"] {
    background: linear-gradient(180deg, rgba(16, 185, 129, 0.06), #fff);
    border-color: rgba(16, 185, 129, 0.35);
}
.um-lc-widget[data-umlc-state="verified"] .um-lc-card-icon {
    background: rgba(16, 185, 129, 0.15);
    color: #059669;
}
.um-lc-widget[data-umlc-state="verified"] .um-lc-card-progress {
    background: rgba(16, 185, 129, 0.15);
}
.um-lc-widget[data-umlc-state="verified"] .um-lc-card-percent {
    color: #059669;
}
.um-lc-widget[data-umlc-state="verified"] .um-lc-widget-fill {
    background: #10b981;
}

/* Start button */
.um-lc-start-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    padding: 12px 18px;
    background: var(--um-lc-accent);
    color: #1f2937;
    border: 0;
    border-radius: 10px;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s, transform 0.05s, background 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}
.um-lc-start-btn:hover:not(:disabled) {
    filter: brightness(0.95);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.um-lc-start-btn:active:not(:disabled) {
    transform: translateY(1px);
}
.um-lc-start-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.um-lc-btn-icon, .um-lc-btn-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
/* Hide the verified checkmark in any state other than verified.
   The triple !important guard prevents any stale v1 stylesheet from showing it
   in the idle/running states. */
.um-lc-start-btn .um-lc-btn-check { display: none !important; }
.um-lc-start-btn[data-state="verified"] .um-lc-btn-check { display: inline-flex !important; }
.um-lc-start-btn[data-state="verified"] .um-lc-btn-icon { display: none !important; }

/* Hide any v1 leftovers that a cached old script might create */
.um-lc-inline-badge { display: none !important; }
.um-lc-mount { display: none !important; }
.um-lc-start-btn[data-state="running"] {
    background: #e5e7eb;
    color: #6b7280;
}
.um-lc-start-btn[data-state="running"] .um-lc-btn-icon::after {
    content: "";
    width: 14px;
    height: 14px;
    margin-left: 4px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: um-lc-spin 0.8s linear infinite;
    display: inline-block;
}
@keyframes um-lc-spin {
    to { transform: rotate(360deg); }
}
.um-lc-start-btn[data-state="verified"] {
    background: #10b981;
    color: #fff;
}

.um-lc-start-btn.um-lc-shake {
    animation: um-lc-shake 0.45s ease;
}
@keyframes um-lc-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.um-lc-form-message {
    display: none;
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(220, 38, 38, 0.08);
    border-left: 3px solid #dc2626;
    color: #b91c1c;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.45;
}
.um-lc-form-message-visible {
    display: block;
    animation: um-lc-fade-in 200ms ease-out;
}

/* ============================================================
 * Submit button locked state - applied to the UM submit button
 * itself while the liveness check has not yet passed.
 * ============================================================ */

.um-lc-submit-locked {
    opacity: 0.55 !important;
    cursor: not-allowed !important;
    pointer-events: none !important; /* prevent click flashing on disabled submits */
    position: relative;
    filter: grayscale(0.3);
}

/* Tiny padlock badge attached to a locked submit button */
.um-lc-submit-locked::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 14px;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='11' width='18' height='11' rx='2'/><path d='M7 11V7a5 5 0 0 1 10 0v4'/></svg>") no-repeat center / contain;
            mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='11' width='18' height='11' rx='2'/><path d='M7 11V7a5 5 0 0 1 10 0v4'/></svg>") no-repeat center / contain;
    opacity: 0.7;
    pointer-events: none;
}

/* When the form is locked, show a subtle inline hint near the submit */
.um-lc-form-locked input[type="submit"].um-lc-submit-locked,
.um-lc-form-locked button[type="submit"].um-lc-submit-locked,
.um-lc-form-locked .um-button.um-lc-submit-locked {
    padding-right: 38px; /* room for the padlock icon */
}

/* Body lock when modal open */
body.um-lc-modal-open {
    overflow: hidden;
}

/* Modal */
.um-lc-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    animation: um-lc-fade-in 200ms ease-out;
}
@keyframes um-lc-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.um-lc-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 11, 18, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.um-lc-panel {
    position: relative;
    width: min(440px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    background: var(--um-lc-bg);
    border-radius: var(--um-lc-radius);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: um-lc-pop 280ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes um-lc-pop {
    from { transform: translateY(20px) scale(0.96); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

.um-lc-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    color: var(--um-lc-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 8px;
    z-index: 2;
}
.um-lc-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--um-lc-text);
}

.um-lc-header {
    padding: 22px 24px 8px;
    text-align: center;
}
.um-lc-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--um-lc-text);
}
.um-lc-subtitle {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--um-lc-muted);
    line-height: 1.45;
}

.um-lc-body {
    padding: 16px 24px;
}

/* Big percentage bar at the top of the modal */
.um-lc-percent-wrap {
    padding: 0 24px 6px;
}
.um-lc-percent-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}
.um-lc-percent-label {
    font-size: 12px;
    color: var(--um-lc-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.um-lc-percent-number {
    font-size: 22px;
    font-weight: 700;
    color: var(--um-lc-accent);
    font-variant-numeric: tabular-nums;
    transition: color 0.2s;
}
.um-lc-modal.um-lc-success .um-lc-percent-number {
    color: #10b981;
}
.um-lc-modal.um-lc-error .um-lc-percent-number {
    color: #dc2626;
}
.um-lc-percent-track {
    width: 100%;
    height: 8px;
    background: var(--um-lc-border);
    border-radius: 999px;
    overflow: hidden;
}
.um-lc-percent-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--um-lc-accent), color-mix(in srgb, var(--um-lc-accent) 70%, #fff));
    border-radius: 999px;
    transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.um-lc-modal.um-lc-success .um-lc-percent-fill {
    background: linear-gradient(90deg, #10b981, #34d399);
}

/* Stage with video */
.um-lc-stage {
    display: flex;
    justify-content: center;
    margin-bottom: 14px;
}
.um-lc-video-wrap {
    position: relative;
    width: 260px;
    height: 260px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--um-lc-bg-dark);
    box-shadow: 0 0 0 4px var(--um-lc-bg), 0 8px 28px rgba(0, 0, 0, 0.18);
}
.um-lc-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Mirror so it feels natural for the user */
    transform: scaleX(-1);
}
.um-lc-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: scaleX(-1);
}

/* Progress ring around the video */
.um-lc-frame-ring {
    position: absolute;
    inset: -6px;
    pointer-events: none;
}
.um-lc-frame-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.um-lc-ring-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.18);
    stroke-width: 3;
}
.um-lc-ring-progress {
    fill: none;
    stroke: var(--um-lc-accent);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 301.6;
    stroke-dashoffset: 301.6;
    transition: stroke-dashoffset 0.3s ease;
}

/* Center checkmark on success */
.um-lc-check-icon {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(16, 185, 129, 0.9);
    color: #fff;
    z-index: 3;
}
.um-lc-check-icon svg {
    width: 80px;
    height: 80px;
}
.um-lc-check-icon circle {
    stroke: #fff;
    stroke-width: 2;
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    animation: um-lc-stroke 600ms cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.um-lc-check-icon path {
    stroke: #fff;
    stroke-width: 4;
    stroke-linecap: round;
    fill: none;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    animation: um-lc-stroke 400ms 300ms cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
@keyframes um-lc-stroke {
    to { stroke-dashoffset: 0; }
}
.um-lc-modal.um-lc-success .um-lc-check-icon { display: flex; }
.um-lc-modal.um-lc-success .um-lc-video-wrap { box-shadow: 0 0 0 4px var(--um-lc-bg), 0 8px 28px rgba(16, 185, 129, 0.35); }

/* Status text under the video */
.um-lc-status {
    text-align: center;
    margin: 0 auto;
    min-height: 56px;
}
.um-lc-step {
    font-size: 15px;
    font-weight: 600;
    color: var(--um-lc-text);
    margin-bottom: 4px;
    line-height: 1.35;
}
.um-lc-hint {
    font-size: 13px;
    color: var(--um-lc-muted);
    line-height: 1.4;
    min-height: 18px;
}

/* Eye status indicator */
.um-lc-eye-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px auto 12px;
    padding: 8px 14px;
    background: var(--um-lc-accent-soft);
    border-radius: 999px;
    width: fit-content;
    color: var(--um-lc-text);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}
.um-lc-eye-status[data-state="pending"] {
    background: rgba(107, 114, 128, 0.15);
    color: var(--um-lc-muted);
}
.um-lc-eye-status[data-state="detected"] {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
}
.um-lc-eye-status[data-state="closing"],
.um-lc-eye-status[data-state="closed"] {
    background: rgba(245, 158, 11, 0.15);
    color: #b45309;
}
.um-lc-eye-status[data-state="opened"] {
    background: rgba(16, 185, 129, 0.18);
    color: #047857;
}
.um-lc-eye {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: inherit;
    transition: transform 0.15s;
}
.um-lc-eye-icon-closed { display: none; }
.um-lc-eye[data-state="closed"] .um-lc-eye-icon-open { display: none; }
.um-lc-eye[data-state="closed"] .um-lc-eye-icon-closed { display: inline-block; }
.um-lc-eye[data-state="closed"] { transform: scale(0.9); }
.um-lc-eye[data-state="unknown"] {
    opacity: 0.45;
}

/* Per-challenge live progress meter (for head turns, smile, nod, look up) */
.um-lc-challenge-meter {
    margin-top: 12px;
    padding: 12px 14px;
    background: #f9fafb;
    border: 1px solid var(--um-lc-border);
    border-radius: 10px;
}
.um-lc-challenge-meter-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}
.um-lc-challenge-meter-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--um-lc-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.um-lc-challenge-meter-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--um-lc-accent);
    font-variant-numeric: tabular-nums;
}
.um-lc-challenge-meter-track {
    height: 8px;
    width: 100%;
    background: var(--um-lc-border);
    border-radius: 999px;
    overflow: hidden;
}
.um-lc-challenge-meter-fill {
    height: 100%;
    background: var(--um-lc-accent);
    border-radius: 999px;
    transition: width 0.12s linear; /* fast linear for direct head-pose feedback */
}

/* Error state */
.um-lc-modal.um-lc-error .um-lc-step { color: #b91c1c; }
.um-lc-modal.um-lc-error .um-lc-video-wrap { box-shadow: 0 0 0 4px var(--um-lc-bg), 0 8px 28px rgba(220, 38, 38, 0.3); }

/* Progress dots */
.um-lc-progress-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
}
.um-lc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--um-lc-border);
    transition: background 0.2s, transform 0.2s;
}
.um-lc-dot-active {
    background: var(--um-lc-accent);
    transform: scale(1.3);
}
.um-lc-dot-done {
    background: #10b981;
}

/* Footer buttons */
.um-lc-footer {
    display: flex;
    gap: 10px;
    padding: 16px 24px 22px;
    justify-content: center;
}
.um-lc-btn {
    flex: 1;
    max-width: 200px;
    height: 44px;
    border: 0;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s;
    font-family: inherit;
}
.um-lc-btn:active {
    transform: translateY(1px);
}
.um-lc-btn-primary {
    background: var(--um-lc-accent);
    color: #1f2937;
}
.um-lc-btn-primary:hover {
    filter: brightness(0.95);
}
.um-lc-btn-secondary {
    background: #f3f4f6;
    color: var(--um-lc-text);
}
.um-lc-btn-secondary:hover {
    background: #e5e7eb;
}

/* Small screens */
@media (max-width: 600px) {
    .um-lc-panel {
        width: 100vw;
        max-height: 100vh;
        height: 100vh;
        height: 100dvh; /* dynamic viewport height for mobile browsers with collapsible URL bars */
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    .um-lc-body {
        padding: 10px 16px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .um-lc-header {
        padding: 16px 16px 4px;
    }
    .um-lc-title { font-size: 17px; }
    .um-lc-subtitle { font-size: 12.5px; }
    .um-lc-percent-wrap { padding: 0 16px 4px; }
    .um-lc-percent-number { font-size: 20px; }
    .um-lc-video-wrap {
        width: min(70vw, 240px);
        height: min(70vw, 240px);
    }
    .um-lc-stage { margin-bottom: 10px; }
    .um-lc-eye-status {
        font-size: 12px;
        padding: 6px 12px;
        gap: 8px;
        margin: 6px auto 8px;
    }
    .um-lc-step { font-size: 14px; }
    .um-lc-hint { font-size: 12px; }
    .um-lc-challenge-meter {
        padding: 10px 12px;
        margin-top: 10px;
    }
    .um-lc-challenge-meter-label { font-size: 11px; }
    .um-lc-challenge-meter-value { font-size: 15px; }
    .um-lc-footer {
        padding: 12px 16px 16px;
        gap: 8px;
    }
    .um-lc-btn {
        min-height: 48px; /* WCAG touch target */
        font-size: 15px;
    }
    .um-lc-widget {
        padding: 14px;
    }
    .um-lc-widget-header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .um-lc-card-icon {
        width: 36px;
        height: 36px;
    }
    .um-lc-card-title { font-size: 14px; }
    .um-lc-card-desc { font-size: 12px; }
    .um-lc-start-btn {
        min-height: 52px; /* generous on phones */
        font-size: 15px;
    }
}

/* Landscape phones: shrink video so all UI fits without scrolling */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .um-lc-video-wrap {
        width: 160px;
        height: 160px;
    }
    .um-lc-header { padding: 10px 16px 2px; }
    .um-lc-percent-wrap { padding: 0 16px 4px; }
    .um-lc-percent-number { font-size: 18px; }
    .um-lc-body { padding: 8px 16px; }
    .um-lc-footer { padding: 8px 16px 12px; }
}

/* Dark scheme respect */
@media (prefers-color-scheme: dark) {
    .um-lc-panel {
        --um-lc-bg: #161a22;
        --um-lc-text: #f3f4f6;
        --um-lc-muted: #9ca3af;
        --um-lc-border: #2a2f3a;
    }
    .um-lc-btn-secondary {
        background: #232936;
        color: var(--um-lc-text);
    }
    .um-lc-btn-secondary:hover {
        background: #2c3342;
    }
    .um-lc-widget {
        background: #161a22;
        border-color: #2a2f3a;
        color: #f3f4f6;
    }
    .um-lc-widget .um-lc-card-title { color: #f3f4f6; }
    .um-lc-widget .um-lc-card-desc { color: #9ca3af; }
    .um-lc-widget-track { background: #2a2f3a; }
    .um-lc-percent-track { background: #2a2f3a; }
    .um-lc-challenge-meter {
        background: #1f2530;
        border-color: #2a2f3a;
    }
    .um-lc-challenge-meter-track { background: #2a2f3a; }
}
