:root {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --surface-glass: rgba(30, 41, 59, 0.7);
    --primary-color: #60a5fa;
    /* Lighter blue for better contrast on dark */
    --primary-hover: #3b82f6;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --success-color: #10b981;
    --transition-speed: 0.3s;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Center vertically on Desktop */
    overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Container */
.app-container {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    background: radial-gradient(circle at top right, #1e293b 0%, #0f172a 100%);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    transition: max-width 0.3s ease;
    /* overflow: hidden; Removed global overflow hidden to allow mobile scrolling */
}

/* PC Specific Override via JS class */
body.desktop-mode .app-container {
    max-width: 800px;
    /* Wider container for PC */
    min-height: auto;
    border-radius: 20px;
    margin: 2rem;
    border: 1px solid var(--border-color);
    height: 90vh;
    overflow: hidden;
    /* Only clip on Desktop card mode */
}

/* Header */
.app-header {
    padding: 1.5rem;
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.logo-area svg {
    color: var(--primary-color);
}

/* Step Indicator */
.step-indicator {
    display: flex;
    gap: 0.5rem;
}

.step-dot {
    height: 4px;
    flex: 1;
    background: var(--border-color);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.step-dot.active {
    background: var(--primary-color);
    box-shadow: 0 0 10px rgba(96, 165, 250, 0.4);
}

/* Main Content */
main {
    flex: 1;
    position: relative;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
}

/* Views & Animation */
.view {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    animation: fadeIn var(--transition-speed) ease-out;
}

.view.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.text-center {
    text-align: center;
}

h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

h3 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 2rem;
    max-width: 400px;
}

/* Document Selection */
.card-options {
    display: grid;
    gap: 1rem;
    width: 100%;
    max-width: 500px;
}

/* PC: Side by side cards */
body.desktop-mode .card-options {
    grid-template-columns: 1fr 1fr;
}

.card-btn {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    flex-direction: row;
    /* Mobile default */
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    text-align: left;
    color: inherit;
    position: relative;
    overflow: hidden;
}

/* PC: Vertical cards */
body.desktop-mode .card-btn {
    flex-direction: column;
    text-align: center;
    padding: 2.5rem 1.5rem;
    gap: 1.5rem;
}

.card-btn:hover {
    background: #252f42;
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.icon-box {
    background: rgba(96, 165, 250, 0.1);
    padding: 0.75rem;
    border-radius: 12px;
    color: var(--primary-color);
    transition: transform 0.2s;
}

.card-btn:hover .icon-box {
    transform: scale(1.1);
}

.card-text p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.chevron {
    font-size: 1.5rem;
    color: var(--text-secondary);
    opacity: 0.5;
}

body.desktop-mode .chevron {
    display: none;
}

/* Capture Area */
.capture-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    justify-content: flex-start;
}

.camera-container {
    width: 100%;
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    background: #000;
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    aspect-ratio: 3/4;
    max-height: 45vh;
    /* Reduced from 55vh to fit screens better */
}

#camera-stream {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Overlay & Guide */
.placeholder-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 85%;
    aspect-ratio: 1.58;
    /* Border is now handled dynamically in JS mainly */
    border-radius: 16px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    /* Dimmer */
    pointer-events: none;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* This allows clicks to pass through guide */
.guide-frame {
    width: 100%;
    height: 100%;
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: inherit;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.guide-icon {
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

.scan-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-color);
    animation: scan 3s ease-in-out infinite;
    opacity: 0.0;
    /* Hidden by default unless active? Let's keep it visible for cool effect */
    opacity: 0.7;
}

@keyframes scan {
    0% {
        top: 0%;
        opacity: 0;
    }

    15% {
        opacity: 1;
    }

    85% {
        opacity: 1;
    }

    100% {
        top: 100%;
        opacity: 0;
    }
}

/* Lighting Toast */
.lighting-toast {
    position: absolute;
    top: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    border-radius: 30px;
    padding: 0.6rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    z-index: 20;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.lighting-toast.hidden {
    opacity: 0;
    transform: translate(-50%, -20px);
}

.lighting-toast.warning {
    border-color: #f59e0b;
    color: #fef3c7;
}

.lighting-toast.error {
    border-color: #ef4444;
    color: #fee2e2;
}

/* Controls */
.controls-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding-bottom: 2rem;
}

.capture-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: transparent;
    border: 4px solid rgba(255, 255, 255, 0.2);
    padding: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shutter-ring {
    width: 100%;
    height: 100%;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.1s;
}

.capture-btn:active .shutter-ring {
    transform: scale(0.85);
    background: var(--primary-color);
}

.capture-btn:active {
    border-color: rgba(255, 255, 255, 0.6);
}

/* Desktop Upload Zone */
.fallback-options.desktop-upload-mode {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-zone {
    width: 100%;
    height: 300px;
    border: 2px dashed var(--border-color);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: all 0.3s ease;
    gap: 1rem;
}

.upload-zone:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--primary-color);
}

.upload-icon-circle {
    width: 64px;
    height: 64px;
    background: var(--surface-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.upload-zone h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.upload-zone p {
    color: var(--text-secondary);
}

.file-types {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.7;
    background: var(--surface-color);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
}


/* Regular Mobile Fallback */
.fallback-options:not(.desktop-upload-mode) {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.75rem 1.25rem;
    border-radius: 20px;
    transition: background 0.2s;
}

.btn-text:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

/* Preview */
.preview-container {
    width: 100%;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    background: #000;
    margin-bottom: 2rem;
    background: #000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-height: 50vh;
    /* Limit height */
    display: flex;
    /* Center image if it's smaller */
    align-items: center;
    justify-content: center;
}

#image-preview {
    width: 100%;
    height: 100%;
    max-height: 50vh;
    object-fit: contain;
    /* Ensure it fits without cropping or stretching */
    display: block;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    width: 100%;
    margin-top: auto;
}

.btn {
    flex: 1;
    padding: 1.125rem;
    border-radius: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: var(--primary-color);
    color: #0f172a;
    /* Dark text on bright button */
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.3);
}

.btn-primary:hover {
    background: #93c5fd;
    transform: translateY(-1px);
}

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

.btn-secondary:hover {
    background: #252f42;
}

/* Loading & Success */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 50vh;
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

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

.success-icon {
    width: 90px;
    height: 90px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 2rem;
    color: var(--success-color);
}