/* ===== 基础重置 ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: #f6f3ee;
  color: #1a1a1a;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow-x: hidden;
}

/* ===== 页面切换 ===== */
.page {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px);
  flex-direction: column;
}

.page.active {
  display: flex;
}

/* ===== 首页 ===== */
.home-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.brand {
  margin-bottom: 8px;
}

.brand-logo-img {
  width: 320px;
  max-width: 90vw;
  height: auto;
}

.brand-sub {
  display: none;
}

.app-title-wrap {
  position: relative;
  display: inline-block;
}

.app-title {
  font-size: 28px;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0;
}

.app-version {
  position: absolute;
  top: -4px;
  left: 100%;
  margin-left: 8px;
  font-size: 12px;
  font-weight: 500;
  color: #999;
  background: #e8e5e0;
  padding: 2px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

.app-desc {
  font-size: 14px;
  color: #888;
  margin: 4px 0 16px;
}

.btn-primary {
  width: 100%;
  max-width: 320px;
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  background: #ff6b00;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
}

.btn-primary:active {
  transform: scale(0.96);
  opacity: 0.9;
}

.btn-secondary {
  width: 100%;
  max-width: 320px;
  padding: 14px;
  font-size: 16px;
  font-weight: 500;
  color: #333;
  background: #fff;
  border: 1px solid #d0ccc6;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s;
}

.btn-secondary:active {
  transform: scale(0.96);
}

.privacy-note {
  margin-top: 24px;
  padding: 12px 16px;
  background: #ede9e3;
  border-radius: 8px;
  max-width: 360px;
  width: 100%;
}

.privacy-note p {
  font-size: 12px;
  color: #888;
  line-height: 1.6;
}

/* ===== 摄像头授权提示页 ===== */
.perm-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.perm-logo {
  width: 320px;
  max-width: 90vw;
  height: auto;
  margin-bottom: 4px;
}

.perm-title {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a1a;
}

.perm-text {
  font-size: 14px;
  color: #555;
  line-height: 1.8;
  max-width: 300px;
}

/* ===== 训练页：全屏摄像头 + 浮层 ===== */
#page-training {
  padding: 0;
  overflow: hidden;
  position: relative;
  background: #111;
}

/* 全屏摄像头画面 */
.camera-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  display: none;
}

.camera-video.active {
  display: block;
}

/* 摄像头未开启占位 */
.cam-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  background: #111;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.cam-placeholder.hidden {
  display: none;
}

.cam-placeholder-text {
  font-size: 16px;
  font-weight: 600;
  color: #555;
}

.cam-placeholder-hint {
  font-size: 12px;
  color: #444;
}

/* ===== 识别区域外遮罩 ===== */
.recognition-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  background: rgba(245, 245, 245, 0.65);
  -webkit-clip-path: polygon(
    0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%,
    5% 20%, 5% 95%, 95% 95%, 95% 20%, 5% 20%
  );
  clip-path: polygon(
    0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%,
    5% 20%, 5% 95%, 95% 95%, 95% 20%, 5% 20%
  );
  transition: opacity 0.4s;
}

/* ===== 识别区域虚线框 ===== */
.recognition-area {
  position: absolute;
  left: 5%;
  top: 20%;
  width: 90%;
  height: 75%;
  border: 4px dashed rgba(255, 80, 80, 0.85);
  border-radius: 12px;
  z-index: 3;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.4s;
}

.recognition-label {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
  text-align: center;
  padding: 4px 12px;
  transition: opacity 0.4s;
}

/* 未检测到球 */
.recognition-area.ready {
  border-color: rgba(255, 80, 80, 0.85);
}

.recognition-area.ready .recognition-label {
  color: rgba(255, 140, 140, 0.9);
}

/* 校准中 */
.recognition-area.ready.calibrating {
  border-color: rgba(255, 200, 0, 0.85);
}

.recognition-area.ready.calibrating .recognition-label {
  color: rgba(255, 230, 100, 0.9);
}

/* 准备就绪 */
.recognition-area.ready.calibrated {
  border-color: rgba(0, 220, 80, 0.85);
}

.recognition-area.ready.calibrated .recognition-label {
  color: rgba(100, 255, 140, 0.9);
}

/* 倒计时中 */
.recognition-area.countdown {
  border-color: rgba(255, 107, 0, 0.65);
  border-style: solid;
}

.recognition-area.countdown .recognition-label {
  opacity: 0;
}

/* 训练中 */
.recognition-area.running {
  border-color: rgba(255, 255, 255, 0.25);
  border-style: solid;
}

.recognition-area.running .recognition-label {
  opacity: 0;
}

/* 已暂停 */
.recognition-area.paused {
  border-color: rgba(230, 184, 0, 0.55);
  border-style: dashed;
}

.recognition-area.paused .recognition-label {
  opacity: 0;
}

/* ===== 倒计时显示 ===== */
.countdown-display {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.countdown-number {
  font-size: 120px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
  line-height: 1;
}

/* ===== 左上角 Logo ===== */
.overlay-logo {
  position: absolute;
  top: 16px;
  left: 12px;
  width: 140px;
  height: auto;
  z-index: 10;
  opacity: 1;
}

/* Logo 下方：状态标签 */
.overlay-status {
  position: absolute;
  top: 72px;
  left: 12px;
  z-index: 10;
}

/* 状态标签 */
.status-badge {
  display: inline-block;
  font-size: 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 4px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.status-badge.running {
  background: rgba(255, 107, 0, 0.75);
  border-color: rgba(255, 107, 0, 0.5);
}

.status-badge.paused {
  background: rgba(230, 184, 0, 0.6);
  border-color: rgba(230, 184, 0, 0.4);
}

.status-badge.countdown {
  background: rgba(255, 107, 0, 0.6);
  border-color: rgba(255, 107, 0, 0.4);
}

/* 右上角：数据浮层 */
.overlay-stats {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.overlay-stat-row {
  display: flex;
  gap: 16px;
}

.overlay-stat-item {
  text-align: center;
}

.overlay-stat-item .stat-value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.overlay-stat-item .stat-label {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  margin-top: 1px;
}

/* 左下角：摄像头切换 */
.overlay-cam-info {
  position: absolute;
  bottom: 16px;
  left: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.btn-cam-switch {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s;
  white-space: nowrap;
}

.btn-cam-switch:active {
  transform: scale(0.95);
}

.cam-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  padding-left: 2px;
}

/* 右下角：灵敏度 */
.overlay-sensitivity {
  position: absolute;
  bottom: 16px;
  right: 12px;
  z-index: 10;
}

.btn-sensitivity {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.1s;
  white-space: nowrap;
}

.btn-sensitivity:active {
  transform: scale(0.95);
}

/* 右侧中上：操作按钮组 */
.overlay-controls {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.btn-control {
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  white-space: nowrap;
  text-align: center;
}

.btn-control:active {
  transform: scale(0.96);
}

.btn-toggle {
  color: #fff;
  background: rgba(255, 107, 0, 0.85);
  border-color: rgba(255, 107, 0, 0.5);
  font-size: 16px;
  font-weight: 700;
  padding: 14px 18px;
}

.btn-toggle.running {
  background: rgba(50, 50, 50, 0.85);
  border-color: rgba(255, 255, 255, 0.15);
}

.btn-toggle.paused {
  background: rgba(255, 107, 0, 0.85);
  border-color: rgba(255, 107, 0, 0.5);
}

.btn-toggle.countdown {
  background: rgba(60, 60, 60, 0.85);
  border-color: rgba(255, 255, 255, 0.1);
}

.btn-toggle.disabled {
  background: rgba(60, 60, 60, 0.6);
  border-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.35);
  cursor: not-allowed;
  opacity: 0.7;
}

.btn-reset {
  color: rgba(255, 255, 255, 0.7);
  background: rgba(0, 0, 0, 0.4);
  font-size: 13px;
  padding: 10px 18px;
}

.btn-end {
  color: #fff;
  background: rgba(255, 107, 0, 0.4);
  border-color: rgba(255, 107, 0, 0.3);
  font-size: 13px;
  padding: 10px 18px;
}

/* ===== 大号实时指导提示 ===== */
.guide-message {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  max-width: 80%;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.3s;
}

.guide-text {
  display: inline-block;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.4;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
  padding: 10px 18px;
  border-radius: 14px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.guide-message.running {
  opacity: 0.5;
}

.guide-message.running .guide-text {
  font-size: 15px;
  background: rgba(0, 0, 0, 0.45);
}

/* 识别状态 */
.overlay-detect-status {
  position: absolute;
  right: 12px;
  top: calc(50% + 140px);
  z-index: 10;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  text-align: right;
}

.overlay-detect-status.running {
  color: rgba(255, 107, 0, 0.85);
}

.overlay-detect-status.paused {
  color: rgba(230, 184, 0, 0.85);
}

.overlay-detect-status.ready-ok {
  color: rgba(0, 200, 80, 0.85);
}

/* 调试面板 */
.debug-panel {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  z-index: 10;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, monospace;
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  min-width: 100px;
  display: none;
}

.debug-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  line-height: 1.8;
}

.debug-label {
  color: rgba(255, 255, 255, 0.45);
}

.debug-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ===== 结果页 ===== */
.result-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  overflow-y: auto;
  padding-bottom: 24px;
}

.result-title {
  font-size: 24px;
  font-weight: 700;
  margin-top: 24px;
}

.result-evaluation {
  font-size: 16px;
  color: #fff;
  font-weight: 600;
  background: #ff6b00;
  padding: 6px 20px;
  border-radius: 20px;
}

.result-cards {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 400px;
}

.result-card {
  flex: 1;
  background: #1a1a1a;
  border-radius: 12px;
  padding: 16px 8px;
  text-align: center;
  border: 1px solid #222;
}

.result-card-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.result-card-label {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin-top: 8px;
}

/* 历史记录 */
.history-section {
  width: 100%;
  max-width: 400px;
  margin-top: 16px;
}

.history-title {
  font-size: 15px;
  font-weight: 600;
  color: #555;
  margin-bottom: 10px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #e0ddd8;
}

.history-item-info {
  font-size: 13px;
  color: #888;
}

.history-item-stats {
  text-align: right;
}

.history-item-stats .value {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  font-variant-numeric: tabular-nums;
}

.history-item-stats .label {
  font-size: 11px;
  color: #999;
}

.history-empty {
  font-size: 13px;
  color: #aaa;
  text-align: center;
  padding: 16px;
}

/* ===== 桌面端适配 ===== */
@media (min-width: 600px) {
  #page-home,
  #page-permission,
  #page-result {
    max-width: 480px;
    margin: 0 auto;
  }

  #page-training {
    max-width: none;
    margin: 0;
  }

  .brand-logo-img {
    width: 380px;
  }
}
