:root {
    --bg-dark: #050505;
    --bg-surface: #121212;
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.5);
    --secondary: #1e293b;
    --accent: #8b5cf6;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #10b981;
    --danger: #ef4444;
    --glass: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 20px);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden; /* Prevent scrolling on mobile */
    height: 100vh;
    width: 100vw;
}

.app-container {
    height: 100%;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

/* Progress Bar */
.progress-container {
    padding: 20px 24px;
    background: linear-gradient(to bottom, var(--bg-dark), transparent);
    z-index: 100;
}

.progress-bar {
    height: 4px;
    background: var(--secondary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    width: 33%;
    background: linear-gradient(to right, var(--primary), var(--accent));
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-steps {
    display: flex;
    justify-content: space-between;
}

.step {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    transition: color 0.3s;
}

.step.active {
    color: var(--primary);
}

/* View Management */
.view {
    display: none;
    flex: 1;
    overflow-y: auto;
    width: 100%;
    animation: fadeIn 0.5s ease-out forwards;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* Welcome View */
.welcome-content {
    padding: 40px 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100%;
    text-align: center;
}

.logo-area {
    margin-bottom: 40px;
}

.logo-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    box-shadow: 0 10px 30px var(--primary-glow);
}

.logo-icon i {
    width: 40px;
    height: 40px;
    color: white;
}

.welcome-content h1 {
    font-size: 32px;
    font-weight: 600;
    margin: 0;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.info-card {
    background: var(--glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 24px;
    margin-bottom: 40px;
    width: 100%;
    max-width: 400px;
}

.info-card p {
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 20px;
}

.feature-list {
    list-style: none;
    padding: 0;
    text-align: left;
}

.feature-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 14px;
}

.feature-list i {
    width: 18px;
    height: 18px;
    color: var(--primary);
}

/* Camera View */
.camera-container {
    position: relative;
    flex: 1;
    background: black;
    overflow: hidden;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 60px;
    pointer-events: none;
}

.instruction-box {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: white;
    padding: 10px 20px;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: auto;
    border: 1px solid rgba(255,255,255,0.1);
}

.guide-frame {
    width: 85%;
    aspect-ratio: 1.6/1; /* Typical ID shape */
    border: 2px solid var(--primary);
    border-radius: 16px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5); /* Mask */
    transition: all 0.5s ease;
}

.guide-frame.face {
    aspect-ratio: 1/1.3;
    border-radius: 1000px; /* Oval for face */
    width: 70%;
}

@keyframes successPulse {
    0% { transform: translate(-50%, -50%) scale(1); box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5), 0 0 20px var(--success); }
    50% { transform: translate(-50%, -50%) scale(1.02); box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.4), 0 0 40px var(--success); }
    100% { transform: translate(-50%, -50%) scale(1); box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.5), 0 0 20px var(--success); }
}

.guide-frame.detected {
    border-color: var(--success) !important;
    animation: successPulse 1s infinite !important;
}

#debug-panel {
    pointer-events: none;
    line-height: 1.4;
    border: 1px solid rgba(0, 255, 0, 0.3);
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

#debug-panel span {
    font-weight: bold;
    color: #fff;
}

.camera-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 30px 30px calc(20px + var(--safe-area-inset-bottom));
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    pointer-events: auto;
}

/* Preview View */
.preview-content {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.preview-frame {
    width: 100%;
    max-width: 400px;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    margin: 24px 0;
    background: black;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

#preview-img {
    width: 100%;
    display: block;
}

.preview-actions {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    margin-top: auto;
    padding-bottom: var(--safe-area-inset-bottom);
}

/* Success View */
.success-content {
    padding: 40px 30px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
}

.success-icon {
    width: 100px;
    height: 100px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border-radius: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
}

.success-icon i {
    width: 60px;
    height: 60px;
}

.summary-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    margin: 30px 0;
}

.summary-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 15px;
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-item i {
    color: var(--success);
    width: 20px;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 16px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-large {
    width: 100%;
    padding: 18px;
    font-size: 16px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-primary:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.btn-secondary {
    background: var(--secondary);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}

.btn-icon {
    width: 54px;
    height: 54px;
    border-radius: 50%;
}

.btn-capture {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: white;
    padding: 4px;
    box-shadow: 0 0 20px rgba(255,255,255,0.3);
}

.capture-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid black;
    background: white;
    transition: transform 0.2s;
}

.btn-capture:active .capture-inner {
    transform: scale(0.9);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(10px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(59, 130, 246, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: rotate 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes rotate {
    to { transform: rotate(360deg); }
}

/* Responsive tweaks */
@media (max-width: 380px) {
    .welcome-content h1 { font-size: 28px; }
    .logo-icon { width: 60px; height: 60px; }
    .info-card { padding: 16px; }
}
