/* ============================================
   AR Page Styles
   ============================================ */

#ar-root {
    position: fixed;
    inset: 0;
    background: #000;
    overflow: hidden;
}

#ar-container {
    position: absolute;
    inset: 0;
    z-index: 1;
}

#ar-container video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#ar-container canvas {
    position: absolute;
    inset: 0;
    z-index: 2;
}

/* Utility */
.hidden { display: none !important; }

/* ============ Scan overlay ============ */

.scan-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-frame {
    position: relative;
    width: 200px;
    height: 400px;
    transition: box-shadow 0.4s, border-color 0.4s;
}

.scan-corner {
    position: absolute;
    width: 36px;
    height: 36px;
    border-color: var(--accent-cyan);
    border-style: solid;
}

.scan-corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 8px 0 0 0; }
.scan-corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 8px 0 0; }
.scan-corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 8px; }
.scan-corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 8px 0; }

/* Product mask image inside scan-frame */
.product-mask-img {
    position: absolute;
    inset: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    object-fit: contain;
    opacity: 0.30;
    mix-blend-mode: screen;
    pointer-events: none;
    filter: brightness(1.2);
    transition: opacity 0.35s, filter 0.35s;
    animation: maskPulse 3s ease-in-out infinite;
}

@keyframes maskPulse {
    0%, 100% { opacity: 0.25; }
    50% { opacity: 0.38; }
}

/* Seam line indicator at ~34% from top */
.scan-seam {
    position: absolute;
    left: 8px;
    right: 8px;
    top: 34%;
    height: 1px;
    background: var(--accent-cyan);
    opacity: 0.35;
    pointer-events: none;
    box-shadow: 0 0 6px rgba(0, 220, 255, 0.3);
    transition: opacity 0.35s;
}

/* Alignment feedback — product detected over the mask */
.scan-frame.aligned .product-mask-img {
    opacity: 0.55;
    filter: brightness(1.6) drop-shadow(0 0 14px rgba(16, 185, 129, 0.5));
    animation: none;
}

.scan-frame.aligned .scan-seam {
    background: #10B981;
    opacity: 0.55;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.scan-frame.aligned .scan-corner {
    border-color: #10B981;
    filter: drop-shadow(0 0 6px rgba(16, 185, 129, 0.4));
    transition: border-color 0.3s, filter 0.3s;
}

.scan-hint {
    margin-top: 32px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    animation: pulse 2s ease-in-out infinite;
}

.scan-sub-hint {
    margin-top: 8px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-align: center;
    opacity: 0.55;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* ============ Status bar ============ */

.status-bar {
    position: absolute;
    top: env(safe-area-inset-top, 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    margin-top: 12px;
    transition: all 0.4s ease;
}

.status-bar i { color: var(--accent-cyan); }

.status-bar.found {
    border-color: rgba(16, 185, 129, 0.3);
}

.status-bar.found i { color: #10B981; }

/* ============ Prediction card ============ */

.prediction-card {
    position: absolute;
    bottom: 120px;
    left: 16px;
    right: 16px;
    z-index: 20;
    padding: 28px 24px 24px;
    text-align: center;
    border-radius: var(--radius-xl);
    transform: translateY(calc(100% + 140px));
    opacity: 0;
    transition:
        transform 0.7s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.4s ease;
    background: rgba(10, 10, 30, 0.75);
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.prediction-card.visible {
    transform: translateY(0);
    opacity: 1;
}

.prediction-sparkle {
    margin-bottom: 12px;
    color: var(--accent-amber);
}

.prediction-sparkle i {
    width: 28px;
    height: 28px;
    animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
    50% { transform: scale(1.2) rotate(15deg); opacity: 1; }
}

.prediction-text {
    font-size: 1.1rem;
    font-weight: 500;
    line-height: 1.5;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.prediction-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Glass button */
.glass-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.glass-btn:hover, .glass-btn:active {
    background: rgba(139, 92, 246, 0.35);
    border-color: rgba(139, 92, 246, 0.5);
}

.glass-btn.secondary {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.glass-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* ============ Controls ============ */

.controls {
    position: absolute;
    bottom: 32px;
    left: 16px;
    right: 16px;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.ctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    color: var(--text-primary);
}

.ctrl-btn i { width: 20px; height: 20px; }

.ctrl-btn-primary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
    border: none;
    border-radius: var(--radius-full);
    color: #fff;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

.ctrl-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(139, 92, 246, 0.55);
}

.ctrl-btn-primary:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ============ Loading ============ */

.loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: rgba(5, 5, 16, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.loading-overlay p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.loader-ring {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(139, 92, 246, 0.15);
    border-top-color: var(--accent-purple);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

/* ============ Error overlay ============ */

.error-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(5, 5, 16, 0.9);
}

.error-card {
    padding: 40px 28px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 340px;
}

.error-card i { color: var(--accent-pink); }

.error-card h3 {
    font-size: 1.2rem;
    font-weight: 600;
}

.error-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ============ Tap instruction ============ */

.tap-hint {
    position: absolute;
    bottom: 180px;
    left: 0;
    right: 0;
    z-index: 15;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    pointer-events: none;
    animation: pulse 2s ease-in-out infinite;
}

/* ============ Tap ripple ============ */

.tap-ripple {
    position: absolute;
    width: 10px;
    height: 10px;
    border: 2px solid var(--accent-cyan);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 15;
    animation: rippleOut 0.7s ease-out forwards;
}

@keyframes rippleOut {
    0% { width: 10px; height: 10px; opacity: 1; }
    100% { width: 100px; height: 100px; opacity: 0; }
}
