/* ============================================================
   色彩记忆挑战 — Color Memory Game
   对标 dialed.gg 设计风格：暗色主题、大色块、触控友好
   ============================================================ */

/* ─── CSS 变量 ──────────────────────────────────────────────── */
:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #222240;
  --text: #e0e0e0;
  --text-muted: #8888aa;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.4);
  --success: #00e676;
  --warning: #ffd740;
  --danger: #ff5252;
  --slider-h: 48px;
  --slider-thumb: 28px;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── 主容器 ───────────────────────────────────────────────── */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.hidden {
  display: none !important;
}

/* ─── 通用屏幕容器 ──────────────────────────────────────────── */
.screen {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fadeInUp 0.5s ease;
}

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

/* ─── 首页 ──────────────────────────────────────────────────── */
#intro-screen h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #6c63ff, #ff6584, #ffd740);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#intro-screen .subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 8px;
}

#intro-screen .desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 32px;
  max-width: 360px;
}

.btn-primary {
  padding: 14px 48px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 0 20px var(--accent-glow);
  letter-spacing: 1px;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 32px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ─── 展示阶段 ──────────────────────────────────────────────── */
#display-screen {
  width: 100%;
  max-width: 520px;
}

.color-swatch-large {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 50vh;
  max-height: 50dvh;
  border-radius: var(--radius);
  background: #333;
  box-shadow: var(--shadow);
  transition: background-color 0.6s ease;
  position: relative;
  overflow: hidden;
}

#countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 5rem;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

#countdown.pulse {
  animation: countPulse 0.9s ease;
}

@keyframes countPulse {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0.7; }
}

.round-badge {
  margin-top: 16px;
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 1px;
}

/* ─── 调色阶段 ──────────────────────────────────────────────── */
#adjust-screen {
  width: 100%;
  max-width: 520px;
}

.preview-section {
  margin-bottom: 24px;
}

#preview-swatch {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin: 0 auto 8px;
  background: hsl(180, 50%, 50%);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255,255,255,0.1);
  transition: background-color 0.15s ease;
}

.preview-label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* 滑杆组 */
.sliders-group {
  width: 100%;
  margin-bottom: 20px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
}

.slider-label {
  flex: 0 0 56px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.3;
}

.slider-label small {
  display: block;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.slider-track-wrapper {
  flex: 1;
  position: relative;
}

.slider-track-bg {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 8px;
  border-radius: 4px;
  transform: translateY(-50%);
  pointer-events: none;
  background: #333;
}

/* 自定义 range input */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: var(--slider-h);
  background: transparent;
  cursor: pointer;
  position: relative;
  z-index: 1;
}

/* Webkit thumb */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--slider-thumb);
  height: var(--slider-thumb);
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 0 12px rgba(108, 99, 255, 0.5), 0 2px 6px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: box-shadow var(--transition);
  margin-top: -10px;
}

input[type="range"]::-webkit-slider-thumb:active {
  box-shadow: 0 0 20px rgba(108, 99, 255, 0.8), 0 2px 6px rgba(0,0,0,0.3);
}

/* Firefox thumb */
input[type="range"]::-moz-range-thumb {
  width: var(--slider-thumb);
  height: var(--slider-thumb);
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 0 12px rgba(108, 99, 255, 0.5), 0 2px 6px rgba(0,0,0,0.3);
  cursor: pointer;
}

/* Webkit track */
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
}

/* 色相滑杆特殊轨道 */
#h-track {
  background: linear-gradient(
    to right,
    hsl(0, 70%, 50%),
    hsl(30, 70%, 50%),
    hsl(60, 70%, 50%),
    hsl(120, 70%, 50%),
    hsl(180, 70%, 50%),
    hsl(240, 70%, 50%),
    hsl(300, 70%, 50%),
    hsl(360, 70%, 50%)
  );
}

/* 饱和度滑杆轨道（动态更新） */
#s-track {
  transition: background 0.2s ease;
}

/* 亮度滑杆轨道（动态更新） */
#l-track {
  transition: background 0.2s ease;
}

.slider-value {
  flex: 0 0 42px;
  text-align: right;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.confirm-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 4px;
  margin-bottom: 16px;
}

/* ─── 结果页 ────────────────────────────────────────────────── */
#results-screen {
  width: 100%;
  max-width: 560px;
}

#results-screen h2 {
  font-size: 1.6rem;
  margin-bottom: 20px;
  font-weight: 700;
}

/* 总分区域 */
.total-score-section {
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
}

.total-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

#total-score {
  font-size: 3rem;
  font-weight: 900;
  background: linear-gradient(135deg, #6c63ff, #ff6584);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.total-max {
  font-size: 1.2rem;
  color: var(--text-muted);
}

#total-label {
  font-size: 1rem;
  color: var(--text);
}

/* 分数条 */
.score-bar {
  height: 8px;
  background: #333;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 12px;
}

.score-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--success);
  transition: width 1s ease, background 0.5s ease;
}

/* 百分位 */
#percentile {
  font-size: 1.1rem;
  margin-bottom: 24px;
  color: var(--text);
}

#percentile .estimated {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* 逐轮对比 */
#rounds-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-bottom: 24px;
}

.round-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
  animation: fadeInUp 0.4s ease backwards;
}

.round-card:nth-child(1) { animation-delay: 0.05s; }
.round-card:nth-child(2) { animation-delay: 0.1s; }
.round-card:nth-child(3) { animation-delay: 0.15s; }
.round-card:nth-child(4) { animation-delay: 0.2s; }
.round-card:nth-child(5) { animation-delay: 0.25s; }

.round-card-header {
  flex: 0 0 50px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.round-card-colors {
  display: flex;
  gap: 8px;
  flex: 1;
}

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

.color-swatch-mini {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.color-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.round-card-score {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.score-num {
  font-size: 1.3rem;
  font-weight: 700;
  min-width: 42px;
  text-align: right;
}

.score-emoji {
  font-size: 1.1rem;
}

.score-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 52px;
}

/* 操作按钮区 */
.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-secondary {
  padding: 12px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid #333;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

/* ─── Toast 提示 ────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 28px;
  background: var(--bg-card);
  color: var(--text);
  border-radius: 20px;
  font-size: 0.9rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

#toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* ─── 移动端适配 ────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --slider-h: 56px;
    --slider-thumb: 32px;
  }

  #app {
    padding: 16px;
    justify-content: flex-start;
    padding-top: 40px;
  }

  #intro-screen h1 {
    font-size: 1.6rem;
  }

  .btn-primary {
    padding: 16px 40px;
    font-size: 1.05rem;
  }

  #preview-swatch {
    width: 100px;
    height: 100px;
  }

  .slider-row {
    padding: 12px 14px;
    gap: 10px;
  }

  .slider-label {
    flex: 0 0 48px;
    font-size: 0.8rem;
  }

  .slider-value {
    flex: 0 0 40px;
    font-size: 0.85rem;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 32px;
    height: 32px;
    margin-top: -12px;
  }

  #total-score {
    font-size: 2.4rem;
  }

  .round-card {
    padding: 10px 12px;
    gap: 8px;
  }

  .color-swatch-mini {
    width: 34px;
    height: 34px;
  }

  .score-num {
    font-size: 1.1rem;
    min-width: 36px;
  }

  .actions {
    flex-direction: column;
    width: 100%;
  }

  .btn-secondary {
    width: 100%;
    text-align: center;
  }
}

/* 极小屏 */
@media (max-width: 360px) {
  :root {
    --slider-h: 52px;
    --slider-thumb: 28px;
  }

  .slider-label {
    flex: 0 0 42px;
    font-size: 0.75rem;
  }

  .round-card {
    flex-wrap: wrap;
  }

  .round-card-score {
    width: 100%;
    justify-content: flex-end;
  }
}
