/* ===== CSS Variables ===== */
:root {
    --bg-primary: #f0f2f5;
    --bg-card: #ffffff;
    --bg-video: #e8eaed;
    --accent: #2dd4a8;
    --accent-dark: #20b090;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --heart: #f472b6;
    --heart-bg: rgba(244, 114, 182, 0.1);
    --hrv-green: #34d399;
    --hrv-blue: #60a5fa;
    --stress-yellow: #fbbf24;
    --para-purple: #a78bfa;
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 16px;
    line-height: 1.5;
}

/* Hidden video element */
#videoInput {
    position: absolute;
    top: -9999px;
    left: -9999px;
}

/* ===== App Container ===== */
.app-container {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ===== Phone Frame ===== */
.phone-frame {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* ===== Signal Quality Overlay ===== */
.signal-quality-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px 16px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 100%);
    z-index: 10;
    pointer-events: none;
}

.quality-stars {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.quality-stars .star {
    font-size: 24px;
    color: rgba(255, 255, 255, 0.4);
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: color 0.3s, transform 0.2s;
}

.quality-stars .star.active {
    color: var(--accent);
    text-shadow: 0 0 8px rgba(45, 212, 191, 0.5);
    transform: scale(1.1);
}

/* ===== Video Area ===== */
.video-area {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: var(--bg-video);
    border-radius: var(--radius-md);
    overflow: hidden;
}

#previewCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    z-index: 1;
}

#overlayCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    pointer-events: none;
    z-index: 3;
}

/* ===== Face Position Guide (SVG) ===== */
.face-guide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    transform: scaleX(-1);
}

.face-guide .corner-bracket {
    fill: none;
    stroke: var(--accent);
    stroke-width: 0.8;
    stroke-linecap: round;
}

.face-guide .face-oval {
    fill: none;
    stroke: var(--accent);
    stroke-width: 0.4;
    stroke-dasharray: 2 2;
    opacity: 0.7;
}

.face-guide .center-cross {
    stroke: var(--accent);
    stroke-width: 0.4;
    opacity: 0.7;
}

/* ===== Status Message ===== */
.status-message {
    font-size: 14px;
    font-weight: 600;
    color: white;
    text-align: center;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    min-height: 20px;
}

/* ===== Start Button ===== */
.start-button {
    width: 100%;
    background: var(--accent);
    color: white;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 2px;
    padding: 16px 32px;
    border: none;
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.start-button:hover {
    background: var(--accent-dark);
    transform: scale(1.02);
}

.start-button:active {
    transform: scale(0.98);
}

.start-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Progress Bar ===== */
.progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.progress-track {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent) 0%, #34d399 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(45, 212, 191, 0.4);
}

.progress-percent {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    min-width: 40px;
    text-align: right;
}

/* ===== Metrics Grid ===== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

/* ===== Large Heart Rate Card with Waveform ===== */
.metric-card-large {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

.metric-card-large.heart {
    border-color: var(--heart);
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--heart-bg) 100%);
}

.metric-card-large .metric-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.metric-card-large .metric-icon {
    font-size: 18px;
    color: var(--heart);
}

.metric-card-large .metric-value-inline {
    margin-left: auto;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.metric-card-large .metric-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
}

.metric-card-large .metric-unit {
    font-size: 14px;
    color: var(--text-secondary);
}

.plot-container-inline {
    height: 80px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.plot-container-inline #plotCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ===== Metric Cards ===== */
.metric-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow);
}

.metric-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.metric-icon {
    font-size: 16px;
}

/* Icon colors for each metric card */
.metric-card:nth-child(1) .metric-icon {
    color: var(--accent);  /* Breathing */
}

.metric-card:nth-child(2) .metric-icon {
    color: var(--hrv-green);  /* HRV */
}

.metric-card:nth-child(3) .metric-icon {
    color: var(--stress-yellow);  /* Stress */
}

.metric-card:nth-child(4) .metric-icon {
    color: var(--para-purple);  /* Parasympathetic */
}

.metric-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.metric-value-row {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.metric-unit {
    font-size: 14px;
    color: var(--text-muted);
}

/* ===== Status Line ===== */
.status-line {
    font-size: 14px;
    padding: 0 4px;
}

.status-label {
    font-weight: 600;
    color: var(--text-primary);
}

.status-text {
    color: var(--text-secondary);
}

/* ===== Plot Container ===== */

/* ===== Debug Panel ===== */
.debug-panel {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.debug-panel summary {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    user-select: none;
}

.debug-panel summary:hover {
    color: var(--text-primary);
}

.debug-content {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.debug-content strong {
    color: var(--accent);
}

.debug-content input[type="range"] {
    flex: 1;
    min-width: 100px;
    accent-color: var(--accent);
}

/* ===== Animations ===== */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.metric-card-large.heart .metric-icon {
    animation: pulse 1s ease-in-out infinite;
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
    body {
        padding: 8px;
    }
    
    .phone-frame {
        padding: 16px;
        border-radius: var(--radius-md);
    }
    
    .metric-card {
        padding: 12px;
    }
    
    .metric-value {
        font-size: 24px;
    }
}
