:root {
    --bg-color: #0b0b0f;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.07);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    --primary: #6366f1; /* Indigo */
    --primary-glow: rgba(99, 102, 241, 0.3);
    --accent: #06b6d4;  /* Cyan */
    --accent-glow: rgba(6, 182, 212, 0.3);
    --danger: #ef4444;  /* Red */
    --success: #10b981; /* Green */
    --warning: #f59e0b; /* Amber */
    
    --font-sans: 'Outfit', sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* Background Glowing Elements */
.background-glow {
    position: absolute;
    top: -10%;
    left: -10%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.12) 0%, rgba(6, 182, 212, 0.02) 50%, rgba(0,0,0,0) 100%);
    filter: blur(80px);
    z-index: -1;
    pointer-events: none;
}

/* Header */
.app-header {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 1.8rem;
    filter: drop-shadow(0 0 10px var(--primary-glow));
}

.logo h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 1.5px;
}

.accent-text {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-indicator {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem 1rem;
    border-radius: 99px;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.dot.green { background-color: var(--success); box-shadow: 0 0 8px var(--success); }
.dot.yellow { background-color: var(--warning); box-shadow: 0 0 8px var(--warning); }
.dot.red { background-color: var(--danger); box-shadow: 0 0 8px var(--danger); }

/* Main Container */
.app-container {
    flex: 1;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Glassmorphism Cards */
.card {
    border-radius: 24px;
    padding: 2.2rem;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.glass-panel {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.card:hover {
    border-color: rgba(99, 102, 241, 0.25);
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4), 0 0 20px rgba(99, 102, 241, 0.05);
}

.card-header {
    margin-bottom: 2rem;
}

.card-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
}

.card-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 300;
}

.card-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.card-header-actions h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
}

.card-header-actions p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 300;
}

.step-badge {
    background: linear-gradient(135deg, var(--primary-glow), var(--accent-glow));
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 0.4rem 0.8rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input, 
.form-group select {
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 1rem;
    padding: 0.8rem 1rem;
    outline: none;
    transition: var(--transition-smooth);
}

.form-group input:focus, 
.form-group select:focus {
    border-color: var(--primary);
    background-color: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 10px var(--primary-glow);
}

.form-group select option {
    background-color: #121217;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.9rem 1.8rem;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-full {
    width: 100%;
    grid-column: span 2;
}

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

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
    filter: brightness(1.1);
}

.secondary-btn {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

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

.accent-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.accent-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.5);
}

/* Camera and Video Scanner View */
.scanner-view-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background-color: #060608;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#webcam, #output-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Silhouette Guide Guide Outline */
.guide-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.body-outline {
    width: 60%;
    height: 85%;
    border: 2px dashed rgba(6, 182, 212, 0.4);
    border-radius: 100px / 180px;
    position: relative;
    animation: pulse 2s infinite ease-in-out;
}

.body-outline::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 25%;
    width: 50%;
    height: 20%;
    border: 2px dashed rgba(6, 182, 212, 0.4);
    border-radius: 50%;
}

.body-outline.aligned {
    border-color: var(--success) !important;
    border-style: solid !important;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4), inset 0 0 15px rgba(16, 185, 129, 0.2);
}

.body-outline.aligned::before {
    border-color: var(--success) !important;
    border-style: solid !important;
}

.guide-text {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-align: center;
    white-space: nowrap;
    transition: var(--transition-smooth);
    z-index: 12;
}

.guide-text.aligned {
    color: var(--success) !important;
    font-weight: 700 !important;
    text-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

/* Shutter Flash */
.camera-flash {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
}

.camera-flash.flash-active {
    animation: flash-anim 0.4s ease-out forwards;
}

@keyframes flash-anim {
    0% { opacity: 0.95; }
    100% { opacity: 0; }
}

@keyframes pulse {
    0% { opacity: 0.3; transform: scale(0.98); }
    50% { opacity: 0.8; transform: scale(1.02); }
    100% { opacity: 0.3; transform: scale(0.98); }
}

/* Loading Overlays */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(11, 11, 15, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    z-index: 20;
    transition: var(--transition-smooth);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(99, 102, 241, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite linear;
}

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

.controls-panel {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    justify-content: space-between;
    flex-wrap: wrap;
}

/* Results Grid */
.results-grid {
    display: grid;
    grid-template-columns: 1.2fr 1.8fr;
    gap: 2rem;
}

.gauge-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gauge-container {
    position: relative;
    width: 160px;
    height: 160px;
}

.gauge {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.gauge-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.05);
    stroke-width: 8;
}

.gauge-fill {
    fill: none;
    stroke: url(#gauge-gradient); /* Will define gradient via script or standard colors */
    stroke: var(--primary);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 1.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.gauge-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.gauge-label .value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.gauge-label .desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: -2px;
}

.metrics-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    justify-content: center;
}

.metric-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.2rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 14px;
}

.metric-item .label {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.metric-item .value {
    font-size: 1.1rem;
    font-weight: 700;
}

.metric-item .value.badge {
    background: rgba(6, 182, 212, 0.1);
    color: var(--accent);
    border: 1px solid rgba(6, 182, 212, 0.2);
    padding: 0.25rem 0.6rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.circumferences-card {
    grid-column: span 2;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 20px;
    padding: 1.8rem;
    margin-top: 1rem;
}

.circumferences-card h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.circ-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.circ-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.circ-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.circ-val {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

/* Footers */
.app-footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 300;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    width: 100%;
}

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

/* Responsive adjustments */
@media (max-width: 680px) {
    /* Main Layout Restyling */
    .app-header {
        flex-direction: column;
        gap: 0.8rem;
        padding: 1.25rem 1rem 0.75rem;
        align-items: center;
        text-align: center;
    }
    
    .logo h1 {
        font-size: 1.25rem;
    }
    
    .status-indicator {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }
    
    .app-container {
        padding: 1rem 0.75rem 2.5rem;
        gap: 1.25rem;
    }
    
    .card {
        padding: 1.25rem;
        border-radius: 16px;
    }
    
    .card-header {
        margin-bottom: 1.25rem;
    }
    
    .card-header h2, .card-header-actions h2 {
        font-size: 1.25rem;
    }
    
    .card-header p, .card-header-actions p {
        font-size: 0.85rem;
    }
    
    /* Form Layout */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .btn-full {
        grid-column: span 1;
    }
    
    .form-group input, 
    .form-group select,
    .btn {
        padding: 0.8rem 1rem;
        font-size: 0.9rem;
        height: 48px; /* Touch friendly height */
    }
    
    /* Choice Grid (stacked options but more compact) */
    .choice-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .choice-card {
        padding: 1.25rem;
        gap: 0.5rem;
    }
    
    .choice-icon {
        font-size: 2rem;
    }
    
    .choice-card h3 {
        font-size: 1rem;
    }
    
    /* Upload Grid (Keep side-by-side but make compact) */
    .upload-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .upload-box {
        padding: 1.25rem 0.75rem;
        min-height: 150px;
        border-radius: 12px;
    }
    
    .box-icon {
        font-size: 1.8rem;
        margin-bottom: 0.25rem;
    }
    
    .upload-box h3 {
        font-size: 0.85rem;
    }
    
    .upload-box p {
        font-size: 0.7rem;
    }
    
    /* Scanner Layout & Camera controls grid */
    .scanner-view-container {
        max-height: 60vh;
        border-radius: 12px;
    }
    
    .controls-panel {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-top: 1rem;
    }
    
    /* Capture, Next Step, Process Uploads, Restart buttons take full width */
    #btn-capture, 
    #btn-next-step, 
    #btn-process-uploads, 
    #btn-restart {
        grid-column: span 2;
        width: 100%;
        order: -1; /* Keep primary actions on top */
    }
    
    /* Secondary utility buttons sit side-by-side on the bottom row */
    #btn-upload-file, 
    #btn-flip-camera,
    #btn-back-to-choice,
    #btn-back-to-info {
        grid-column: span 1;
        width: 100%;
        font-size: 0.85rem;
        padding: 0.75rem 0.5rem;
        height: 48px;
    }
    
    /* Override inline width of process button on upload flow */
    #btn-process-uploads {
        width: 100% !important;
    }
    
    /* Results Dashboard */
    .results-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
    
    .gauge-card {
        padding: 1.25rem;
    }
    
    .gauge-container {
        width: 140px;
        height: 140px;
    }
    
    .gauge-label .value {
        font-size: 1.75rem;
    }
    
    .metric-item {
        padding: 0.8rem 1rem;
    }
    
    .metric-item .label {
        font-size: 0.85rem;
    }
    
    .metric-item .value {
        font-size: 0.95rem;
    }
    
    /* Circumferences: Keep 3 columns side-by-side but compact */
    .circumferences-card {
        grid-column: span 1;
        padding: 1.25rem;
        margin-top: 0.5rem;
    }
    
    .circumferences-card h3 {
        font-size: 0.85rem;
        margin-bottom: 0.8rem;
    }
    
    .circ-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    
    .circ-item {
        padding: 0.75rem 0.25rem;
        border-radius: 8px;
    }
    
    .circ-label {
        font-size: 0.7rem;
    }
    
    .circ-val {
        font-size: 0.95rem;
    }
}

/* Choice Grid */
.choice-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-top: 1rem;
}

.choice-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-primary);
}

.choice-card:hover {
    background: rgba(99, 102, 241, 0.05);
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(99, 102, 241, 0.1);
}

.choice-icon {
    font-size: 2.5rem;
}

.choice-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.choice-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 300;
}

/* Upload Grid */
.upload-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.upload-box {
    background: rgba(255, 255, 255, 0.01);
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 220px;
}

.upload-box:hover {
    border-color: var(--accent);
    background: rgba(6, 182, 212, 0.02);
}

.box-icon {
    font-size: 2.2rem;
    margin-bottom: 0.75rem;
    display: inline-block;
}

.upload-box h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.upload-box p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.preview-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #060608;
    z-index: 5;
}

