/* ==================== 全局变量与重置 ==================== */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: rgba(30, 30, 50, 0.85);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --text-primary: #e8e8f0;
    --text-secondary: #a0a0b8;
    --text-muted: #6b6b80;
    --accent-purple: #7c3aed;
    --accent-purple-light: #a78bfa;
    --accent-green: #22c55e;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-blue: #3b82f6;
    --border-color: rgba(255, 255, 255, 0.08);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(124, 58, 237, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(59, 130, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(34, 197, 94, 0.04) 0%, transparent 50%);
}

/* ==================== 布局 ==================== */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px;
}

.app-header {
    text-align: center;
    margin-bottom: 28px;
}

.app-header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-purple-light), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

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

/* ==================== 模型切换按钮 ==================== */
.model-switcher {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 24px;
}

.model-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 32px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(12px);
    min-width: 180px;
}

.model-btn:hover {
    border-color: var(--accent-purple);
    background: rgba(124, 58, 237, 0.1);
    transform: translateY(-2px);
}

.model-btn.active {
    border-color: var(--accent-purple);
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.2), rgba(59, 130, 246, 0.1));
    color: var(--text-primary);
    box-shadow: 0 0 20px rgba(124, 58, 237, 0.2);
}

.model-icon {
    font-size: 1.5rem;
}

.model-name {
    font-size: 1rem;
    font-weight: 600;
}

.model-desc {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ==================== 主内容区 ==================== */
.main-content {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}

/* ==================== 视频区域 ==================== */
.video-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* 镜像 */
}

.video-container canvas#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    transform: scaleX(-1); /* 镜像匹配 */
}

/* 倒计时覆盖 */
.countdown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    z-index: 10;
    transition: opacity 0.3s;
}

.countdown-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.countdown-number {
    font-size: 10rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 0 40px rgba(239, 68, 68, 0.8), 0 0 80px rgba(239, 68, 68, 0.4);
    animation: pulse-countdown 1s ease-in-out infinite;
}

@keyframes pulse-countdown {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* 无摄像头提示 */
.no-camera {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: var(--bg-secondary);
    z-index: 5;
}

.no-camera.hidden {
    display: none;
}

.no-camera-icon {
    font-size: 3rem;
    opacity: 0.5;
}

.no-camera p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.retry-btn {
    padding: 8px 24px;
    background: var(--accent-purple);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.retry-btn:hover {
    background: var(--accent-purple-light);
}

/* 状态栏 */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    font-size: 0.85rem;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.status-indicator.waiting {
    background: var(--accent-orange);
    box-shadow: 0 0 6px var(--accent-orange);
}

.status-indicator.detecting {
    background: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
    animation: blink 1.5s infinite;
}

.status-indicator.countdown {
    background: var(--accent-red);
    box-shadow: 0 0 6px var(--accent-red);
    animation: blink 0.5s infinite;
}

.status-indicator.cooldown {
    background: var(--accent-blue);
    box-shadow: 0 0 6px var(--accent-blue);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.status-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.fps-display {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.model-loading {
    color: var(--accent-orange);
    animation: blink 1s infinite;
}

.model-loading.hidden {
    display: none;
}

/* ==================== 信息面板 ==================== */
.info-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.result-card, .photos-card, .help-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px;
    backdrop-filter: blur(12px);
}

.result-card h3, .photos-card h3, .help-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--text-primary);
}

/* 检测结果 */
.gesture-label {
    font-size: 1.6rem;
    font-weight: 700;
    text-align: center;
    padding: 12px 0;
    color: var(--text-muted);
    transition: color 0.3s;
}

.gesture-label.peace {
    color: var(--accent-green);
}

.gesture-label.palm {
    color: var(--accent-orange);
}

.gesture-label.background {
    color: var(--text-muted);
}

.confidence-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.confidence-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.confidence-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--accent-purple), var(--accent-blue));
    transition: width 0.2s ease;
}

.confidence-value {
    font-size: 0.85rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    width: 40px;
    text-align: right;
    color: var(--text-secondary);
}

/* 照片画廊 */
.photo-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-purple);
    color: white;
    font-size: 0.7rem;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    padding: 0 6px;
    margin-left: 6px;
}

.photo-gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
}

.photo-gallery::-webkit-scrollbar {
    width: 4px;
}

.photo-gallery::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.empty-gallery {
    grid-column: 1 / -1;
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.photo-thumb {
    aspect-ratio: 4/3;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border-color);
    transition: transform 0.2s, border-color 0.2s;
}

.photo-thumb:hover {
    transform: scale(1.05);
    border-color: var(--accent-purple);
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 帮助 */
.help-card ul {
    list-style: none;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.help-card li {
    padding: 4px 0;
    line-height: 1.5;
}

/* ==================== 闪光特效 ==================== */
.flash-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.1s;
}

.flash-overlay.active {
    opacity: 0.8;
    transition: opacity 0s;
}

/* ==================== 底部 ==================== */
.app-footer {
    text-align: center;
    margin-top: 32px;
    padding: 16px;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
}

/* ==================== 响应式 ==================== */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .info-panel {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .result-card, .photos-card, .help-card {
        flex: 1;
        min-width: 200px;
    }
}

@media (max-width: 600px) {
    .app-header h1 {
        font-size: 1.4rem;
    }

    .model-switcher {
        flex-direction: column;
        align-items: center;
    }

    .model-btn {
        min-width: 250px;
    }

    .info-panel {
        flex-direction: column;
    }

    .countdown-number {
        font-size: 6rem;
    }
}
