:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --primary-color: #3b82f6;
    --accent-color: #8b5cf6;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --font-family: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
    background: radial-gradient(circle at top left, #1e1b4b, #0f172a);
}

.app-container {
    width: 100%;
    max-width: 500px;
    padding: 2rem;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    position: relative;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* Camera */

.camera-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.input_video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.output_canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
}

/* Face frame */

.overlay-guide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.face-frame {
    width: 60%;
    height: 65%;
    border: 2px dashed rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.face-frame.active {
    border-color: var(--success-color);
    border-style: solid;
    box-shadow: 0 0 20px var(--success-color);
}

/* Spinner */

.spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: none;
}

@keyframes spin {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Status & debug */

.status-panel {
    margin-bottom: 1.5rem;
}

.metric-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.label {
    font-size: 0.85rem;
    font-weight: 600;
    min-width: 60px;
    text-align: left;
}

.progress-bar {
    flex-grow: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.fill {
    height: 100%;
    width: 0%;
    background: var(--warning-color);
    transition: width 0.2s ease, background-color 0.3s ease;
}

.info-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    min-height: 1.2em;
    margin-bottom: 1rem;
}

.debug-panel {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: left;
}

.debug-item span {
    color: var(--primary-color);
    font-weight: bold;
}

/* Controls */

.controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
}

.btn.primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-small {
    padding: 0.45rem 1.1rem;
    font-size: 0.9rem;
}

.device-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

/* Selfie captured overlay */

.captured-result {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    border-radius: 24px;
}

.captured-result.hidden {
    display: none;
}

.captured-result img {
    max-width: 100%;
    max-height: 60%;
    border-radius: 12px;
    margin: 1.5rem 0;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border: 2px solid var(--success-color);
}

.captured-result h2 {
    color: var(--success-color);
    margin-bottom: 0.5rem;
}

.captured-actions {
    display: flex;
    gap: 0.75rem;
}

/* Loading overlay */

.lib-loading {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: radial-gradient(circle at top, #1f2933 0, #0b1016 60%, #000 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    color: #f9fafb;
    transition: opacity 0.4s ease;
}

.lib-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

.lib-loading-card {
    background: rgba(15, 23, 42, 0.92);
    padding: 20px 28px;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.65);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 230px;
}

.lib-spinner {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 3px solid rgba(148, 163, 184, 0.4);
    border-top-color: #22c55e;
    animation: lib-spin 0.8s linear infinite;
    margin-bottom: 4px;
}

@keyframes lib-spin {
    to {
        transform: rotate(360deg);
    }
}

.lib-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.lib-subtitle {
    font-size: 13px;
    font-weight: 400;
    color: #cbd5f5;
}

.lib-subtitle span#lib-countdown {
    font-weight: 600;
    color: #22c55e;
}

.hidden {
    display: none !important;
}

/* Document step */

.document-section {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.9rem 1rem 1rem;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.35);
    text-align: left;
}

.document-section h2 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.document-section p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.doc-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.7rem;
}

.doc-result-container {
    margin-top: 0.5rem;
    min-height: 120px;
    padding: 0.5rem;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px dashed rgba(148, 163, 184, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
}

.doc-result-container canvas {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.doc-placeholder {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

.doc-actions {
    margin-top: 0.7rem;
    display: flex;
    justify-content: flex-end;
}

/* Step transitions */

#step-selfie,
#step-doc {
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#step-doc.hidden {
    opacity: 0;
    transform: translateY(8px);
}

#step-selfie.hidden {
    opacity: 0;
    transform: translateY(-8px);
}