:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #a5b4fc;
    --accent: #8b5cf6;
    --success: #10b981;
    --success-bg: #d1fae5;
    --warning: #f59e0b;
    --warning-bg: #fef3c7;
    --danger: #ef4444;
    --danger-bg: #fee2e2;
    --info: #3b82f6;
    --info-bg: #dbeafe;
    --male: #3b82f6;
    --male-bg: rgba(59, 130, 246, 0.08);
    --female: #ec4899;
    --female-bg: rgba(236, 72, 153, 0.08);
    --bg: #f0f2f5;
    --card: #ffffff;
    --text: #1e293b;
    --text-2: #64748b;
    --text-3: #94a3b8;
    --border: #e2e8f0;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
    --r: 16px;
    --r-sm: 10px;
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display',
        'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    line-height: 1.5;
}

.app {
    max-width: 500px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

/* ===== Header ===== */
.header {
    text-align: center;
    padding: 52px 20px 28px;
    margin: 0 -16px 16px;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 40%, #ec4899 100%);
    border-radius: 0 0 28px 28px;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -20%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -15%;
    width: 160px;
    height: 160px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 50%;
}

.header-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    position: relative;
    z-index: 1;
}

.header-icon svg {
    width: 100%;
    height: 100%;
}

.header h1 {
    color: #fff;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 2px;
    position: relative;
    z-index: 1;
}

.subtitle {
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    margin-top: 8px;
    position: relative;
    z-index: 1;
}

/* ===== Status Bar ===== */
.status-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--card);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--text-2);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warning);
    flex-shrink: 0;
    animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.ready {
    background: var(--success);
    animation: none;
}

.status-dot.error {
    background: var(--danger);
    animation: none;
}

.usage-notice {
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid #fcd34d;
    border-radius: var(--r-sm);
    background: var(--warning-bg);
    color: #78350f;
    font-size: 12px;
    line-height: 1.65;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* ===== Cards ===== */
.card {
    background: var(--card);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
    animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-top h3 {
    font-size: 16px;
    font-weight: 600;
}

/* ===== Upload ===== */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--r-sm);
    padding: 36px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    margin-bottom: 16px;
}

.upload-area:active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.04);
}

.upload-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    color: var(--primary-light);
}

.upload-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-3);
}

.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    border-radius: var(--r-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:active {
    background: var(--primary-dark);
    transform: scale(0.97);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
}

.btn-secondary:active {
    background: var(--border);
    transform: scale(0.97);
}

.btn-accent {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
}

.btn-accent:active {
    transform: scale(0.97);
    opacity: 0.9;
}

.btn-block {
    width: 100%;
    margin-top: 16px;
}

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

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    padding: 4px 8px;
    border-radius: 6px;
}

.btn-link:active {
    background: rgba(99, 102, 241, 0.08);
}

/* ===== Canvas ===== */
.canvas-wrap {
    border-radius: var(--r-sm);
    overflow: hidden;
    background: #f8fafc;
    border: 1px solid var(--border);
}

.canvas-wrap canvas {
    display: block;
    width: 100%;
    height: auto;
}

/* ===== Step Header ===== */
.step-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.step-num {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.step-desc {
    font-size: 12px;
    color: var(--text-3);
}

/* ===== Info Box ===== */
.info-box {
    margin-top: 14px;
    padding: 12px 14px;
    background: var(--bg);
    border-radius: var(--r-sm);
    font-size: 13px;
    color: var(--text-2);
    line-height: 1.7;
}

.info-box .tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    margin-right: 4px;
}

.tag-success { background: var(--success-bg); color: #065f46; }
.tag-warning { background: var(--warning-bg); color: #92400e; }
.tag-info { background: var(--info-bg); color: #1e40af; }
.tag-danger { background: var(--danger-bg); color: #991b1b; }
.tag-male { background: var(--male-bg); color: var(--male); }
.tag-female { background: var(--female-bg); color: var(--female); }

/* ===== Face Detail Card ===== */
.face-card {
    background: var(--card);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
    animation: fadeUp 0.4s ease;
    border-left: 4px solid var(--primary);
}

.face-card.male {
    border-left-color: var(--male);
}

.face-card.female {
    border-left-color: var(--female);
}

.face-card.child {
    border-left-color: var(--success);
}

.face-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.face-avatar {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

.face-avatar canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.face-meta {
    flex: 1;
    min-width: 0;
}

.face-meta h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.face-meta p {
    font-size: 12px;
    color: var(--text-3);
}

.gender-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.gender-badge.male {
    background: linear-gradient(135deg, rgba(59,130,246,0.12), rgba(59,130,246,0.06));
    color: var(--male);
}

.gender-badge.female {
    background: linear-gradient(135deg, rgba(236,72,153,0.12), rgba(236,72,153,0.06));
    color: var(--female);
}

.gender-badge.child {
    background: linear-gradient(135deg, rgba(16,185,129,0.12), rgba(16,185,129,0.06));
    color: var(--success);
}

.gender-badge svg {
    width: 16px;
    height: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.detail-item {
    padding: 12px;
    border-radius: var(--r-sm);
    background: var(--bg);
    text-align: center;
}

.detail-item .detail-label {
    font-size: 11px;
    color: var(--text-3);
    margin-bottom: 4px;
}

.detail-item .detail-value {
    font-size: 18px;
    font-weight: 700;
}

.detail-item .detail-value.male { color: var(--male); }
.detail-item .detail-value.female { color: var(--female); }
.detail-item .detail-value.child { color: var(--success); }
.detail-item .detail-value.age { color: var(--accent); }

.confidence-bar {
    margin-top: 12px;
}

.confidence-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-3);
    margin-bottom: 6px;
}

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

.confidence-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
}

.confidence-fill.male {
    background: linear-gradient(90deg, #60a5fa, #3b82f6);
}

.confidence-fill.female {
    background: linear-gradient(90deg, #f472b6, #ec4899);
}

.confidence-fill.child {
    background: linear-gradient(90deg, #34d399, #10b981);
}

/* ===== Stats ===== */
.stats-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.stat-item {
    padding: 14px 10px;
    border-radius: var(--r-sm);
    text-align: center;
}

.stat-item.purple {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(139, 92, 246, 0.08));
}

.stat-item.blue {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(37, 99, 235, 0.08));
}

.stat-item.pink {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.08), rgba(219, 39, 119, 0.08));
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-item.purple .stat-value { color: var(--primary); }
.stat-item.blue .stat-value { color: var(--male); }
.stat-item.pink .stat-value { color: var(--female); }
.stat-item.green { background: linear-gradient(135deg, rgba(16,185,129,0.08), rgba(5,150,105,0.08)); }
.stat-item.green .stat-value { color: var(--success); }

.stat-label {
    font-size: 12px;
    color: var(--text-3);
}

/* ===== Loading Overlay ===== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.overlay-content {
    text-align: center;
    color: #fff;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.overlay-content p {
    font-size: 15px;
    margin-bottom: 16px;
}

.progress-bar {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto;
}

.progress-fill {
    height: 100%;
    background: #fff;
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

/* ===== Dark Mode ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --card: #1e293b;
        --text: #f1f5f9;
        --text-2: #94a3b8;
        --text-3: #64748b;
        --border: #334155;
        --male-bg: rgba(59, 130, 246, 0.15);
        --female-bg: rgba(236, 72, 153, 0.15);
    }

    .upload-area { border-color: var(--border); }
    .canvas-wrap { background: #0f172a; }
    .info-box { background: rgba(0, 0, 0, 0.2); }
    .detail-item { background: rgba(0, 0, 0, 0.2); }
}

@media (min-width: 500px) {
    .app { padding: 0 24px 48px; }
    .header { margin: 0 -24px 20px; }
}
