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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0a0a0f;
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

h1 {
    font-size: 1.8rem;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #00f5d4, #00bbf9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #888;
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.container {
    position: relative;
    width: 100%;
    max-width: 720px;
    aspect-ratio: 4 / 3;
    border-radius: 16px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 8px 32px rgba(0, 245, 212, 0.15);
    border: 1px solid rgba(0, 245, 212, 0.2);
}

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

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* 雷达图 canvas 恢复正常文档流 */
.emotion-radar {
    position: relative !important;
    width: 220px;
    height: 220px;
    display: block;
    pointer-events: auto;
}

.controls {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

button {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

#startBtn {
    background: linear-gradient(135deg, #00f5d4, #00bbf9);
    color: #0a0a0f;
}

#startBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 245, 212, 0.4);
}

#startBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.toggle-btn {
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid rgba(0, 245, 212, 0.3);
}

.toggle-btn.active {
    background: rgba(0, 245, 212, 0.15);
    border-color: #00f5d4;
    color: #00f5d4;
}

.toggle-btn:hover {
    border-color: #00f5d4;
}

.info {
    display: flex;
    gap: 20px;
    margin-top: 16px;
    font-size: 0.85rem;
    color: #888;
}

.info span {
    color: #00f5d4;
}

.status {
    margin-top: 16px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    color: #888;
}

.status.error {
    background: rgba(255, 80, 80, 0.1);
    color: #ff5050;
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #00f5d4;
    font-size: 0.9rem;
}

.posture-panel {
    margin-top: 20px;
    width: 100%;
    max-width: 720px;
    padding: 16px 20px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.posture-panel.good {
    background: rgba(0, 245, 136, 0.12);
    border-color: rgba(0, 245, 136, 0.5);
}

.posture-panel.warn {
    background: rgba(255, 209, 102, 0.12);
    border-color: rgba(255, 209, 102, 0.5);
}

.posture-panel.bad {
    background: rgba(255, 80, 80, 0.12);
    border-color: rgba(255, 80, 80, 0.5);
}

.posture-title {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.posture-msg {
    font-size: 1.1rem;
    font-weight: 600;
}

.posture-panel.good .posture-msg { color: #00f588; }
.posture-panel.warn .posture-msg { color: #ffd166; }
.posture-panel.bad .posture-msg { color: #ff5050; }

.posture-detail {
    font-size: 0.8rem;
    color: #888;
    margin-top: 6px;
}

/* ===== 心理评估仪表盘 ===== */
.psych-dashboard {
    margin-top: 32px;
    width: 100%;
    max-width: 720px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    clear: both;
}

@media (max-width: 600px) {
    .psych-dashboard { grid-template-columns: 1fr; }
    .emotion-card-body { flex-direction: column; }
    .emotion-radar-wrap { flex: 0 0 auto; width: 100%; max-width: 260px; }
    .emotion-values { width: 100%; }
}

.psych-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 16px 18px;
    transition: border-color 0.3s ease;
}

.psych-card.full-width {
    grid-column: 1 / -1;
}

.psych-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.psych-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #e0e0e0;
}

.psych-card-score {
    font-size: 1.1rem;
    font-weight: 700;
}

.psych-card-source {
    font-size: 0.7rem;
    color: #666;
    margin-top: 8px;
    line-height: 1.4;
    font-style: italic;
}

/* 情绪雷达图 */
.emotion-card-body {
    display: flex;
    flex-direction: row;
    gap: 20px;
    align-items: center;
}

.emotion-radar-wrap {
    flex: 0 0 220px;
    width: 220px;
    order: 1;
}

.emotion-values {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    order: 2;
}

.emotion-value-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
}

.emotion-value-name {
    width: 36px;
    color: #ccc;
    flex-shrink: 0;
}

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

.emotion-value-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}

.emotion-value-pct {
    width: 32px;
    text-align: right;
    color: #888;
    flex-shrink: 0;
}

.emotion-labels {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    margin-top: 8px;
    font-size: 0.72rem;
}

.emotion-label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #aaa;
}

.emotion-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* 条形进度条 */
.bar-wrap {
    margin-top: 4px;
}

.bar-row {
    margin-bottom: 8px;
}

.bar-row:last-child { margin-bottom: 0; }

.bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: #aaa;
    margin-bottom: 3px;
}

.bar-track {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
}

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

/* 综合总览 */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    text-align: center;
}

.overview-item {
    padding: 8px 4px;
}

.overview-val {
    font-size: 1.3rem;
    font-weight: 700;
}

.overview-name {
    font-size: 0.72rem;
    color: #888;
    margin-top: 2px;
}

/* ===== 报告区域 ===== */
.report-section {
    margin-top: 24px;
    width: 100%;
    max-width: 720px;
}

.report-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 16px;
}

.report-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.report-btn.generate {
    background: linear-gradient(135deg, #00f5d4, #00bbf9);
    color: #0a0a0f;
}

.report-btn.generate:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 245, 212, 0.4);
}

.report-btn.download {
    background: linear-gradient(135deg, #a78bfa, #7c3aed);
    color: #fff;
}

.report-btn.download:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4);
}

.report-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.report-preview-wrap {
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #0d0d14;
    display: none;
}

.report-preview-wrap.visible {
    display: block;
}

#reportCanvas {
    width: 100%;
    height: auto;
    display: block;
}

/* WebSocket 连接状态指示器 */
.ws-status {
    margin-top: 12px;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.82rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

.ws-status.connecting {
    background: rgba(255, 209, 102, 0.1);
    color: #ffd166;
}
.ws-status.connecting .ws-dot { background: #ffd166; }

.ws-status.connected {
    background: rgba(0, 245, 136, 0.1);
    color: #00f588;
}
.ws-status.connected .ws-dot { background: #00f588; }

.ws-status.disconnected {
    background: rgba(255, 80, 80, 0.1);
    color: #ff5050;
}
.ws-status.disconnected .ws-dot { background: #ff5050; }

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

.countdown-ring {
    position: relative;
    width: 140px;
    height: 140px;
}

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

.countdown-ring-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 6;
}

.countdown-ring-progress {
    fill: none;
    stroke: #00f5d4;
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 339.292;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear;
}

.countdown-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 700;
    color: #00f5d4;
}

.countdown-label {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 12px;
}

/* 测试中隐藏仪表盘 */
.psych-dashboard.testing-hidden {
    display: none !important;
}

/* 测试完成后显示结果 */
.posture-panel.result-mode {
    background: rgba(0, 245, 212, 0.12);
    border-color: rgba(0, 245, 212, 0.5);
}

.posture-panel.result-mode .posture-msg { color: #00f5d4; }

/* AI 解读样式 */
.ai-interpretation {
    background: rgba(0, 245, 212, 0.08);
    border: 1px solid rgba(0, 245, 212, 0.3);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    max-width: 720px;
    width: 100%;
}

.ai-interpretation-title {
    font-size: 1rem;
    font-weight: 600;
    color: #00f5d4;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-interpretation-content {
    font-size: 0.85rem;
    color: #ccc;
    line-height: 1.7;
}

.ai-interpretation-loading {
    color: #ffd166;
    font-size: 0.85rem;
}
