/* ============================================================
 * 感官记忆挑战平台 — 时间感知游戏 样式
 * ============================================================
 * 移动端优先，暗色主题，大触控目标。
 * 核心体验：按住阶段无视觉参考，纯内部时钟感知。
 */

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

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #6c6c80;
  --accent: #7c5ce7;
  --accent-glow: rgba(124, 92, 231, 0.4);
  --success: #00d68f;
  --danger: #ff6b6b;
  --warning: #ffa94d;
  --ring-track: #2a2a3e;
  --ring-fill: #7c5ce7;
  --border-radius: 12px;
  --transition: 0.3s ease;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── 游戏容器 ─────────────────────────────────────────────── */
.game-container {
  width: 100%;
  max-width: 480px;
  padding: 16px 20px var(--safe-bottom);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ─── 头部 ────────────────────────────────────────────────── */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.game-header .round-indicator {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

.game-header .total-score {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color var(--transition);
}
.back-link:hover {
  color: var(--text-primary);
}

/* ─── 通用面板 ─────────────────────────────────────────────── */
.panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.panel.hidden {
  display: none;
}

/* ─── 开始面板 ─────────────────────────────────────────────── */
#readyPanel {
  justify-content: center;
  text-align: center;
  gap: 24px;
}

.game-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.game-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 320px;
}

/* ─── 按钮通用 ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background var(--transition);
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 14px 40px;
  box-shadow: 0 4px 16px var(--accent-glow);
  font-size: 1.05rem;
}

.btn-primary:hover {
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 32px;
  border: 1px solid rgba(255,255,255,0.1);
}

.btn-secondary:hover {
  background: #1e2a4a;
}

/* ─── 观看阶段 ─────────────────────────────────────────────── */
#watchPanel {
  justify-content: center;
  gap: 24px;
}

.watch-hint {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}

.target-display {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  font-family: var(--font-mono);
  text-align: center;
  letter-spacing: 2px;
}

.target-unit {
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ─── 进度环 ───────────────────────────────────────────────── */
.progress-ring-container {
  position: relative;
  width: 200px;
  height: 200px;
}

.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring .ring-track {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 8;
}

.progress-ring .ring-fill {
  fill: none;
  stroke: var(--ring-fill);
  stroke-width: 8;
  stroke-linecap: round;
}

.progress-ring .pulse-ring {
  fill: none;
  stroke: var(--ring-fill);
  stroke-width: 2;
  opacity: 0;
  transform-origin: center;
}

/* 脉冲动画 */
@keyframes pulse {
  0% {
    r: 90;
    opacity: 0.6;
    stroke-width: 2;
  }
  100% {
    r: 105;
    opacity: 0;
    stroke-width: 1;
  }
}

/* ─── 按住阶段 ─────────────────────────────────────────────── */
#holdPanel {
  justify-content: center;
  gap: 20px;
}

.hold-instruction {
  font-size: 1.1rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
}

/* 按住按钮 — 核心交互元素 */
.hold-button {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 3px solid var(--accent);
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, background 0.1s ease, border-color 0.1s ease, box-shadow 0.1s ease;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.hold-button::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.1s ease, box-shadow 0.1s ease;
}

/* 按下状态 */
.hold-button.pressed {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: scale(0.92);
  box-shadow: 0 0 40px var(--accent-glow), 0 0 80px rgba(124, 92, 231, 0.2);
}

.hold-button.pressed::before {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  animation: hold-ring 0.8s ease-out infinite;
}

@keyframes hold-ring {
  0% {
    inset: -8px;
    opacity: 0.8;
  }
  100% {
    inset: -20px;
    opacity: 0;
  }
}

.hold-button.disabled {
  pointer-events: none;
  opacity: 0.5;
}

.hold-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-height: 1.2em;
  text-align: center;
}

/* ─── 结果面板 ─────────────────────────────────────────────── */
#resultPanel {
  gap: 12px;
}

.result-card {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
}

.result-row .label {
  color: var(--text-secondary);
}

.result-row .value {
  font-weight: 700;
  font-family: var(--font-mono);
}

/* 误差颜色 */
.error-positive {
  color: var(--danger);
}
.error-negative {
  color: var(--warning);
}
.error-zero {
  color: var(--success);
}

/* 分数展示 */
.score-display {
  text-align: center;
  padding: 12px 0;
}

.score-number {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  font-family: var(--font-mono);
}

.score-label {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* 可视化对比条 */
.comparison-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.bar-label {
  width: 36px;
  color: var(--text-secondary);
  text-align: right;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 16px;
  background: var(--ring-track);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

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

.bar-target {
  background: var(--text-muted);
}

.bar-over {
  background: var(--danger);
}

.bar-under {
  background: var(--warning);
}

.bar-perfect {
  background: var(--success);
}

/* 偏差提示 */
.bias-note {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-secondary);
  padding: 8px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
}

/* ─── 汇总面板 ─────────────────────────────────────────────── */
#summaryPanel {
  gap: 16px;
}

.summary-card {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.summary-title {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  color: var(--text-primary);
}

.summary-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  text-align: center;
  padding: 12px 8px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--border-radius);
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  font-family: var(--font-mono);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.grade-display {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  padding: 10px;
}

.evaluation {
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  padding: 12px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--border-radius);
}

/* 明细表格 */
.breakdown-table {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.breakdown-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.breakdown-row:nth-child(even) {
  background: rgba(255,255,255,0.04);
}

.breakdown-round {
  color: var(--text-muted);
  width: 50px;
}
.breakdown-target {
  color: var(--text-secondary);
  width: 80px;
  text-align: center;
}
.breakdown-actual {
  color: var(--text-primary);
  width: 80px;
  text-align: center;
}
.breakdown-error {
  font-weight: 700;
  width: 70px;
  text-align: center;
}
.breakdown-score {
  font-weight: 700;
  color: var(--accent);
  width: 50px;
  text-align: right;
}

/* ─── 响应式 ───────────────────────────────────────────────── */
@media (min-width: 768px) {
  .game-container {
    padding: 24px 32px;
    gap: 24px;
  }

  .game-title {
    font-size: 2rem;
  }

  .game-subtitle {
    font-size: 1.05rem;
  }

  .btn {
    font-size: 1.1rem;
  }

  .btn-primary {
    padding: 16px 48px;
  }

  .hold-button {
    width: 200px;
    height: 200px;
    font-size: 1.3rem;
  }

  .target-display {
    font-size: 3.5rem;
  }

  .progress-ring-container {
    width: 240px;
    height: 240px;
  }

  .score-number {
    font-size: 3.5rem;
  }
}

/* ─── 暗色主题过渡动画 ─────────────────────────────────────── */
.panel {
  animation: fadeIn 0.3s ease;
}

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

/* ─── 微信兼容 ──────────────────────────────────────────────── */
/* 防止微信内置浏览器长按出现菜单 */
img, svg {
  -webkit-touch-callout: none;
}

/* 微信字体适配 */
@media screen and (max-width: 480px) {
  body {
    font-size: 15px;
  }
}
