/* ===== CSS Variables ===== */
:root {
  --primary: #6C5CE7;
  --primary-dark: #5A4BD1;
  --primary-light: #A29BFE;
  --secondary: #FD79A8;
  --accent: #FDCB6E;
  --success: #00B894;
  --danger: #E17055;
  --dark: #2D3436;
  --gray: #636E72;
  --light: #DFE6E9;
  --bg: #F8F9FA;
  --card-bg: #FFFFFF;
  --shadow: 0 8px 32px rgba(0,0,0,0.10);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  background: linear-gradient(135deg, #e0e7ff 0%, #fce4ec 50%, #e8f5e9 100%);
  min-height: 100vh;
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== App Container ===== */
.app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  position: relative;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(20px);
  box-shadow: 0 0 60px rgba(108,92,231,0.08);
  display: flex;
  flex-direction: column;
}

@media (min-width: 768px) {
  .app-container {
    min-height: 90vh;
    margin: 5vh auto;
    border-radius: 32px;
    overflow: hidden;
    max-width: 440px;
    box-shadow: var(--shadow);
  }
}

/* ===== Header ===== */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 20px 24px 18px;
  position: relative;
  overflow: hidden;
}

.app-header::after {
  content: '';
  position: absolute;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  top: -60px; right: -60px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 1;
}

.app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

.app-title span { color: var(--accent); }

.header-stats {
  display: flex;
  gap: 16px;
  font-size: 13px;
  opacity: 0.9;
}

.header-stats span { display: flex; align-items: center; gap: 4px; }

.progress-bar {
  margin-top: 14px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ===== Pages ===== */
.page {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn 0.4s ease;
}

.page.active { display: flex; }

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

@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes confetti-fall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(80px) rotate(720deg); opacity: 0; }
}

/* ===== Home Page ===== */
.home-page {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 20px 0;
}

.home-icon {
  font-size: 100px;
  margin-bottom: 20px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.home-page h1 {
  font-size: 36px;
  font-weight: 800;
  color: var(--dark);
  margin-bottom: 8px;
}

.home-page h1 span { background: linear-gradient(135deg, var(--primary), var(--secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

.home-page .subtitle {
  font-size: 15px;
  color: var(--gray);
  margin-bottom: 32px;
  line-height: 1.6;
}

.home-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  margin-bottom: 28px;
}

.home-feature {
  background: var(--card-bg);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.home-feature .feat-icon { font-size: 28px; margin-bottom: 6px; }
.home-feature .feat-label { font-size: 12px; color: var(--gray); line-height: 1.4; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  border: none;
  border-radius: 30px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  width: 100%;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 16px rgba(108,92,231,0.3);
}

.btn-primary:hover { box-shadow: 0 6px 24px rgba(108,92,231,0.4); transform: translateY(-2px); }

.btn-secondary {
  background: var(--card-bg);
  color: var(--dark);
  border: 2px solid var(--light);
}

.btn-secondary:hover { border-color: var(--primary-light); }

.btn-success {
  background: linear-gradient(135deg, var(--success), #00a381);
  color: white;
  box-shadow: 0 4px 16px rgba(0,184,148,0.3);
}

.btn-small {
  padding: 10px 20px;
  font-size: 14px;
  width: auto;
}

.btn-icon {
  width: 44px; height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  font-size: 20px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover { background: rgba(255,255,255,0.25); }

/* ===== Avatar Display ===== */
.avatar-container {
  text-align: center;
  margin-bottom: 20px;
}

.avatar-card {
  width: 200px;
  height: 200px;
  margin: 0 auto 16px;
  border-radius: 28px;
  background: linear-gradient(135deg, #f5f3ff, #fff0f6);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(108,92,231,0.12);
  position: relative;
  overflow: hidden;
  transition: var(--transition);
}

.avatar-card.shake { animation: shake 0.5s ease; }

.avatar-card .q-mark {
  font-size: 80px;
  opacity: 0.6;
  color: var(--primary-light);
}

.avatar-svg {
  width: 100%;
  height: 100%;
  padding: 16px;
}

.avatar-label {
  font-size: 13px;
  color: var(--gray);
  margin-top: 4px;
}

.avatar-hint {
  font-size: 14px;
  color: var(--gray);
  background: rgba(108,92,231,0.06);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}

/* ===== Timer ===== */
.timer-bar {
  height: 4px;
  background: var(--light);
  border-radius: 2px;
  margin-bottom: 20px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--accent), var(--danger));
  border-radius: 2px;
  transition: width 0.3s linear;
  width: 100%;
}

.timer-fill.warning { background: var(--accent); }
.timer-fill.danger { background: var(--danger); }

/* ===== Options ===== */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.option-btn {
  padding: 14px 12px;
  border: 2px solid var(--light);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  transition: var(--transition);
  text-align: center;
  color: var(--dark);
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary-light);
  background: rgba(108,92,231,0.04);
  transform: translateY(-2px);
}

.option-btn:active:not(:disabled) { transform: scale(0.97); }

.option-btn.selected {
  border-color: var(--primary);
  background: rgba(108,92,231,0.08);
}

.option-btn.correct {
  border-color: var(--success);
  background: rgba(0,184,148,0.1);
  color: var(--success);
}

.option-btn.wrong {
  border-color: var(--danger);
  background: rgba(225,112,85,0.1);
  color: var(--danger);
  animation: shake 0.4s ease;
}

.option-btn:disabled { cursor: default; opacity: 0.7; }

.option-btn.reveal-correct {
  border-color: var(--success);
  background: rgba(0,184,148,0.08);
}

/* ===== Result Page ===== */
.result-page { align-items: center; text-align: center; }

.result-icon {
  font-size: 64px;
  margin-bottom: 12px;
  animation: popIn 0.5s ease;
}

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

.result-title.correct { color: var(--success); }
.result-title.wrong { color: var(--danger); }

.result-subtitle {
  font-size: 14px;
  color: var(--gray);
  margin-bottom: 20px;
}

.result-comparison {
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
  margin-bottom: 20px;
  width: 100%;
}

.compare-item {
  flex: 1;
  max-width: 140px;
}

.compare-item .compare-frame {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  margin-bottom: 6px;
  box-shadow: var(--shadow-sm);
}

.compare-item .compare-frame.q-frame {
  background: linear-gradient(135deg, #f5f3ff, #e8e0ff);
  border: 2px solid var(--primary-light);
}

.compare-item .compare-frame.real-frame {
  background: linear-gradient(135deg, #fff0f6, #ffe0f0);
  border: 2px solid var(--secondary);
}

.compare-item .compare-label {
  font-size: 12px;
  color: var(--gray);
}

.compare-vs {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary-light);
}

.result-person {
  font-size: 20px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 2px;
}

.result-dept {
  font-size: 13px;
  color: var(--gray);
  margin-bottom: 20px;
}

.result-score {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 24px;
}

.result-score .label {
  font-size: 14px;
  font-weight: 400;
  color: var(--gray);
}

.combo-badge {
  display: inline-block;
  background: linear-gradient(135deg, var(--accent), #E17055);
  color: white;
  padding: 4px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
  animation: popIn 0.4s ease;
}

/* ===== End Page ===== */
.end-page { align-items: center; text-align: center; justify-content: center; }

.end-trophy {
  font-size: 80px;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

.end-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 8px;
}

.end-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  width: 100%;
  margin-bottom: 24px;
}

.end-stat {
  background: var(--card-bg);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: var(--radius-sm);
  padding: 16px 8px;
  box-shadow: var(--shadow-sm);
}

.end-stat .stat-num {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
}

.end-stat .stat-label {
  font-size: 12px;
  color: var(--gray);
  margin-top: 4px;
}

.end-message {
  font-size: 15px;
  color: var(--gray);
  margin-bottom: 24px;
  line-height: 1.6;
  padding: 0 12px;
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* ===== Leaderboard Page ===== */
.leaderboard-page { padding: 0; }

.lb-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.lb-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--dark);
}

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

.lb-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(0,0,0,0.04);
  transition: var(--transition);
}

.lb-item:hover { transform: translateX(4px); }

.lb-item:first-child {
  background: linear-gradient(135deg, #fff9e6, #fff3cc);
  border-color: var(--accent);
}

.lb-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  background: var(--light);
  color: var(--gray);
  flex-shrink: 0;
}

.lb-item:first-child .lb-rank {
  background: var(--accent);
  color: #fff;
  font-size: 14px;
}

.lb-item:nth-child(2) .lb-rank { background: #e8e8e8; }
.lb-item:nth-child(3) .lb-rank { background: #f0d5b0; }

.lb-avatar {
  font-size: 24px;
  flex-shrink: 0;
}

.lb-info { flex: 1; }

.lb-info .lb-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--dark);
}

.lb-info .lb-dept {
  font-size: 12px;
  color: var(--gray);
}

.lb-score {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

/* ===== Confetti ===== */
.confetti-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1000;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 2px;
  animation: confetti-fall 1.5s ease-out forwards;
}

/* ===== Settings Page ===== */
.settings-page { padding: 0; }

.settings-group {
  margin-bottom: 20px;
}

.settings-group h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--light);
}

.settings-item:last-child { border-bottom: none; }

.settings-item .setting-label {
  font-size: 15px;
  color: var(--dark);
}

.settings-item .setting-desc {
  font-size: 12px;
  color: var(--gray);
}

.settings-item select {
  padding: 6px 12px;
  border: 1px solid var(--light);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--dark);
}

.settings-item select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Footer / Bottom Bar ===== */
.app-footer {
  padding: 16px 20px 20px;
  text-align: center;
}

.app-footer small {
  font-size: 11px;
  color: var(--gray);
  opacity: 0.6;
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.mt-auto { margin-top: auto; }
.gap { margin-bottom: 12px; }

/* ===== Responsive ===== */
@media (max-width: 400px) {
  .app-header { padding: 16px 18px; }
  .app-title { font-size: 18px; }
  .main-content { padding: 18px 16px; }
  .avatar-card { width: 160px; height: 160px; }
  .home-icon { font-size: 70px; }
  .home-page h1 { font-size: 28px; }
  .options-grid { gap: 8px; }
  .option-btn { padding: 12px 10px; font-size: 14px; }
  .result-comparison { gap: 10px; }
  .compare-item { max-width: 110px; }
  .compare-item .compare-frame { font-size: 40px; }
}
