/* ============================================================
 * 感官记忆挑战平台 — 形状记忆游戏 样式
 * ============================================================
 * 移动端优先，暗色主题，大触控滑杆。
 * 核心体验：Canvas 绘制形状 + 滑杆调节参数复现。
 */

/* ─── 重置 & 基础 ──────────────────────────────────────────── */
*, *::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;
  --border-radius: 12px;
  --transition: 0.3s ease;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
  --slider-track: #2a2a3e;
  --slider-thumb: #7c5ce7;
}

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: 16px;
  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);
}

/* ─── 观察面板 ─────────────────────────────────────────────── */
#watchPanel {
  justify-content: center;
  gap: 16px;
}

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

.watch-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* Canvas 容器 */
.shape-canvas-wrapper {
  position: relative;
  width: 340px;
  height: 320px;
  max-width: 100%;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.shape-canvas-wrapper canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* 倒计时条 */
.countdown-bar-container {
  width: 100%;
  max-width: 340px;
  height: 4px;
  background: var(--slider-track);
  border-radius: 2px;
  overflow: hidden;
}

.countdown-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 100%;
}

/* ─── 调整面板 ─────────────────────────────────────────────── */
#adjustPanel {
  gap: 12px;
}

.adjust-instruction {
  font-size: 1rem;
  color: var(--text-secondary);
  text-align: center;
  font-weight: 600;
}

/* 预览画布（调整阶段） */
.preview-wrapper {
  width: 280px;
  height: 260px;
  max-width: 100%;
}

/* ─── 滑杆区域 ─────────────────────────────────────────────── */
.sliders-container {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 0;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.slider-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  min-width: 60px;
  text-align: right;
}

/* 自定义滑杆样式 — 移动端大触控目标 */
.slider-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px; /* 大触控区域 */
  background: transparent;
  cursor: pointer;
  outline: none;
}

/* 滑杆轨道 */
.slider-input::-webkit-slider-runnable-track {
  height: 8px;
  background: var(--slider-track);
  border-radius: 4px;
}

.slider-input::-moz-range-track {
  height: 8px;
  background: var(--slider-track);
  border-radius: 4px;
  border: none;
}

/* 滑杆滑块（拇指） */
.slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--slider-thumb);
  border: 3px solid #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
  cursor: pointer;
  margin-top: -14px;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.slider-input::-webkit-slider-thumb:active {
  transform: scale(1.15);
  box-shadow: 0 0 20px var(--accent-glow);
}

.slider-input::-moz-range-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--slider-thumb);
  border: 3px solid #fff;
  box-shadow: 0 2px 8px var(--accent-glow);
  cursor: pointer;
}

/* Firefox 轨道 */
.slider-input::-moz-range-progress {
  height: 8px;
  background: var(--accent);
  border-radius: 4px;
}

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

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

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

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

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

/* 并排形状对比 */
.shape-compare {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.shape-compare-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.shape-compare-item canvas {
  width: 140px;
  height: 130px;
  background: var(--bg-secondary);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.compare-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.shape-compare-vs {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  padding: 0 4px;
}

/* 参数误差行 */
.param-errors {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.per-label {
  color: var(--text-muted);
  width: 60px;
}

.per-target {
  color: var(--text-secondary);
  width: 80px;
  text-align: center;
}

.per-user {
  color: var(--text-primary);
  width: 80px;
  text-align: center;
}

.per-error {
  font-weight: 700;
  width: 50px;
  text-align: right;
}

.error-low {
  color: var(--success);
}

.error-mid {
  color: var(--warning);
}

.error-high {
  color: var(--danger);
}

/* 偏差提示 */
.bias-note {
  text-align: center;
  font-size: 0.85rem;
  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.9rem;
  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;
  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-type {
  color: var(--text-secondary);
  flex: 1;
  text-align: center;
}

.breakdown-error {
  font-weight: 700;
  width: 80px;
  text-align: center;
}

.breakdown-score {
  font-weight: 700;
  color: var(--accent);
  width: 50px;
  text-align: right;
}

/* ─── 面板过渡动画 ─────────────────────────────────────────── */
.panel {
  animation: fadeIn 0.3s ease;
}

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

/* ─── 响应式 ───────────────────────────────────────────────── */
@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;
  }

  .shape-canvas-wrapper {
    width: 380px;
    height: 350px;
  }

  .preview-wrapper {
    width: 320px;
    height: 290px;
  }

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

  .slider-input {
    height: 44px;
  }

  .slider-input::-webkit-slider-thumb {
    width: 40px;
    height: 40px;
    margin-top: -16px;
  }

  .slider-input::-moz-range-thumb {
    width: 40px;
    height: 40px;
  }
}

@media (min-width: 1024px) {
  .game-container {
    max-width: 560px;
  }
}

/* ─── 微信兼容 ──────────────────────────────────────────────── */
img, svg, canvas {
  -webkit-touch-callout: none;
}

@media screen and (max-width: 480px) {
  body {
    font-size: 15px;
  }

  .shape-canvas-wrapper {
    width: 300px;
    height: 280px;
  }

  .preview-wrapper {
    width: 260px;
    height: 240px;
  }
}

@media screen and (max-width: 360px) {
  .shape-canvas-wrapper {
    width: 280px;
    height: 260px;
  }

  .preview-wrapper {
    width: 240px;
    height: 220px;
  }

  .shape-compare-item canvas {
    width: 120px;
    height: 110px;
  }
}
