* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #00ff88;
  --primary-dark: #00cc6a;
  --accent: #4ecdc4;
  --bg: #0a0a1a;
  --bg2: #12122a;
  --card: #1a1a3e;
  --text: #e0e0e0;
  --text-light: #aaa;
  --text-muted: #666;
  --border: rgba(0,255,136,0.15);
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --max-w: 500px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; justify-content: center; align-items: center; }

/* ===== Welcome ===== */
.welcome-container {
  text-align: center;
  padding: 40px 24px;
  max-width: var(--max-w);
  width: 100%;
}
.logo {
  font-size: 80px;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 0 24px rgba(0,255,136,0.5));
  margin-bottom: 16px;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
.welcome-container h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}
.subtitle { font-size: 16px; color: var(--text-light); margin-bottom: 4px; }
.desc { font-size: 13px; color: var(--text-muted); margin-bottom: 32px; }

/* ===== Form ===== */
.register-form { margin-bottom: 20px; }
.input-group { margin-bottom: 12px; }
.input-group input, .input-group select {
  width: 100%; padding: 14px 16px; border: 2px solid var(--border);
  border-radius: 12px; font-size: 16px; outline: none;
  background: var(--card); color: var(--text); transition: border-color 0.2s;
}
.input-group input:focus, .input-group select:focus { border-color: var(--primary); }
.input-group select { appearance: none; cursor: pointer; }

/* ===== Buttons ===== */
.btn-primary {
  width: 100%; padding: 16px; border: none; border-radius: 12px;
  font-size: 18px; font-weight: 600; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #0a0a1a; transition: all 0.2s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,255,136,0.3); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-secondary {
  padding: 12px 24px; border: 2px solid var(--border); border-radius: 12px;
  font-size: 16px; cursor: pointer; background: transparent; color: var(--text);
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-secondary:disabled { opacity: 0.3; cursor: not-allowed; }

/* ===== Test Screen ===== */
#screen-test { flex-direction: column; }
#screen-test.active { display: flex; }
.test-container { width: 100%; max-width: var(--max-w); margin: 0 auto; padding: 0 16px; flex: 1; display: flex; flex-direction: column; }
.progress-bar {
  position: relative; height: 6px; background: var(--card); border-radius: 3px;
  margin: 20px 0 24px; overflow: visible;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 3px; transition: width 0.3s;
}
.progress-text {
  position: absolute; right: 0; top: -20px; font-size: 13px; color: var(--text-muted);
}
.question-card {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 20px 0;
}
.question-text {
  font-size: 20px; font-weight: 600; line-height: 1.5; margin-bottom: 24px;
  text-align: center; color: var(--text);
}
.options { display: flex; flex-direction: column; gap: 12px; }
.option-btn {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  border: 2px solid var(--border); border-radius: 12px; background: var(--card);
  cursor: pointer; transition: all 0.2s; text-align: left; color: var(--text);
  font-size: 15px;
}
.option-btn:hover { border-color: var(--primary); background: rgba(0,255,136,0.05); }
.option-btn.selected { border-color: var(--primary); background: rgba(0,255,136,0.1); }
.option-key {
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0;
  background: var(--bg2); color: var(--text-light);
}
.option-btn.selected .option-key { background: var(--primary); color: #0a0a1a; }
.option-text { flex: 1; }
.nav-buttons { display: flex; gap: 12px; padding: 20px 0; }
.nav-buttons button { flex: 1; }

/* ===== Loading ===== */
.loading-container { text-align: center; padding: 40px; }
.loading-lobster { font-size: 80px; animation: float 2s ease-in-out infinite; }
.loading-container h2 { margin: 24px 0; color: var(--text); font-size: 20px; }
.loading-bar { width: 200px; height: 4px; background: var(--card); border-radius: 2px; margin: 0 auto; overflow: hidden; }
.loading-fill { width: 30%; height: 100%; background: var(--primary); border-radius: 2px; animation: loading 1.5s ease-in-out infinite; }
@keyframes loading { 0% { transform: translateX(-100%); } 100% { transform: translateX(400%); } }

/* ===== Result ===== */
#screen-result { padding: 24px; }
#screen-result.active { display: block; }
.result-container { max-width: var(--max-w); margin: 0 auto; }
.result-header { text-align: center; margin-bottom: 24px; }
.result-header h1 { font-size: 28px; color: var(--primary); margin-bottom: 8px; }
.result-desc { font-size: 15px; color: var(--text-light); line-height: 1.6; }
.result-count { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.result-lobster-info {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  justify-content: center; margin-bottom: 24px;
}
.result-lobster-info span:first-child { font-weight: 600; }
.tag {
  padding: 4px 10px; border-radius: 20px; font-size: 12px;
  background: var(--card); border: 1px solid var(--border); color: var(--text-light);
}
.result-intro { font-size: 13px; color: var(--text-muted); width: 100%; text-align: center; }

.result-section {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; margin-bottom: 16px;
}
.result-section h3 { font-size: 16px; color: var(--primary); margin-bottom: 12px; }
.portrait-text { font-size: 14px; line-height: 1.8; color: var(--text-light); white-space: pre-line; }

.radar-section {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; margin-bottom: 16px; text-align: center;
}
.radar-section h3 { font-size: 16px; color: var(--primary); margin-bottom: 12px; }
#radar-canvas { max-width: 100%; }

.scores-detail {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; margin-bottom: 16px;
}
.scores-detail h3 { font-size: 16px; color: var(--primary); margin-bottom: 16px; }
.dim-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.dim-name { width: 80px; font-size: 13px; color: var(--text-light); text-align: right; flex-shrink: 0; }
.dim-track { flex: 1; height: 8px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
.dim-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 4px; transition: width 0.5s; }
.dim-val { width: 30px; font-size: 13px; color: var(--text-muted); text-align: right; }

.achievement { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.ach-icon { font-size: 24px; }
.achievement strong { display: block; font-size: 14px; color: var(--text); }
.achievement p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.result-score {
  text-align: center; padding: 24px; margin-bottom: 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
}
.score-label { display: block; font-size: 14px; color: var(--text-muted); margin-bottom: 8px; }
.score-value { font-size: 56px; font-weight: 700; color: var(--primary); }

.result-link { margin-bottom: 16px; text-align: center; }
.result-link p { font-size: 14px; color: var(--text-muted); margin-bottom: 8px; }
.link-box { display: flex; gap: 8px; }
.link-box input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: var(--card); color: var(--text);
}
.btn-copy {
  padding: 10px 16px; border: none; border-radius: 8px; cursor: pointer;
  background: var(--primary); color: #0a0a1a; font-weight: 600; font-size: 13px;
}

.result-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.result-actions .btn-primary { flex: 1 1 100%; }
.result-actions .btn-secondary { flex: 1 1 calc(33% - 8px); text-align: center; }

/* ===== Modal ===== */
.modal { display: none; position: fixed; inset: 0; z-index: 1000; align-items: center; justify-content: center; }
.modal.active { display: flex; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.modal-content {
  position: relative; z-index: 1; background: var(--card); border-radius: 16px;
  padding: 24px; max-width: 400px; width: 90%; max-height: 90vh; overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; color: var(--text); }
.modal-close-btn { background: none; border: none; color: var(--text-muted); font-size: 24px; cursor: pointer; }
.share-card-wrapper { text-align: center; margin-bottom: 16px; }
.share-card-wrapper img { max-width: 100%; border-radius: 8px; }
.share-card-actions { text-align: center; }

/* ===== Leaderboard ===== */
#screen-leaderboard { padding: 24px; }
#screen-leaderboard.active { display: block; }
.leaderboard-container { max-width: var(--max-w); margin: 0 auto; }
.leaderboard-container h1 { text-align: center; font-size: 24px; color: var(--primary); margin-bottom: 20px; }
.lb-filter { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.lb-time-filter { display: flex; gap: 4px; }
.lb-range-btn {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: 20px;
  background: transparent; color: var(--text-light); cursor: pointer; font-size: 13px;
}
.lb-range-btn.active { background: var(--primary); color: #0a0a1a; border-color: var(--primary); }
#lb-type-filter {
  flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--card); color: var(--text); font-size: 13px;
}
.lb-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 8px;
}
.lb-rank { font-size: 20px; width: 36px; text-align: center; flex-shrink: 0; }
.lb-info { flex: 1; }
.lb-info strong { display: block; font-size: 15px; color: var(--text); }
.lb-type { font-size: 12px; color: var(--text-muted); }
.lb-score { font-size: 20px; font-weight: 700; color: var(--primary); }
.leaderboard-actions { display: flex; gap: 12px; margin-top: 16px; justify-content: center; }

/* ===== PK ===== */
.pk-result { text-align: center; }
.pk-result h2 { font-size: 24px; color: var(--primary); margin-bottom: 20px; }
.pk-header { display: flex; align-items: center; justify-content: center; gap: 20px; margin-bottom: 20px; }
.pk-player { font-size: 16px; font-weight: 600; color: var(--text); }
.pk-player small { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.pk-vs { font-size: 24px; font-weight: 700; color: var(--primary); }
.pk-dims { margin-bottom: 20px; }
.pk-dim { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 8px 0; }
.pk-score { width: 40px; font-size: 16px; font-weight: 600; color: var(--text-light); }
.pk-score.pk-win { color: var(--primary); }
.pk-label { width: 100px; text-align: center; font-size: 13px; color: var(--text-muted); }
.pk-winner { font-size: 20px; font-weight: 700; color: var(--primary); margin-top: 12px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: -60px; left: 50%; transform: translateX(-50%);
  padding: 12px 24px; border-radius: 12px; font-size: 14px; z-index: 2000;
  transition: bottom 0.3s; background: var(--card); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow);
}
.toast.show { bottom: 40px; }
.toast.success { border-color: var(--primary); }
.toast.error { border-color: #ff4444; }

/* ===== Resume Bar ===== */
.resume-bar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  margin-top: 16px;
}
.resume-bar span { flex: 1; font-size: 14px; }
.resume-bar button {
  padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 13px;
}
#btn-resume { background: var(--primary); color: #0a0a1a; }
#btn-discard { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .welcome-container h1 { font-size: 26px; }
  .question-text { font-size: 17px; }
  .result-header h1 { font-size: 24px; }
  .score-value { font-size: 48px; }
  .result-actions .btn-secondary { flex: 1 1 calc(50% - 6px); }
}

/* Quit button */
.test-top-bar { display: flex; align-items: center; gap: 12px; padding: 16px 0 0; }
.btn-quit {
  background: none; border: none; color: var(--text-muted); font-size: 14px;
  cursor: pointer; padding: 4px 8px; flex-shrink: 0;
}
.btn-quit:hover { color: var(--text); }
.test-top-bar .progress-bar { flex: 1; margin: 0; }

/* ===== iOS Safe Area ===== */
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.test-container { -webkit-overflow-scrolling: touch; }
.nav-buttons { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.result-actions { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

/* ===== 入场动画 ===== */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes countUp { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: scale(1); } }
@keyframes achPop { 0% { opacity: 0; transform: scale(0.3); } 60% { transform: scale(1.1); } 100% { opacity: 1; transform: scale(1); } }

#screen-result.active .result-type { animation: fadeInUp 0.6s ease-out; }
#screen-result.active .result-portrait { animation: fadeInUp 0.6s ease-out 0.2s both; }
#screen-result.active .radar-container { animation: fadeInUp 0.6s ease-out 0.4s both; }
#screen-result.active .scores-detail { animation: fadeInUp 0.6s ease-out 0.6s both; }
#screen-result.active .result-achievements { animation: fadeInUp 0.6s ease-out 0.8s both; }
#screen-result.active #total-score { animation: countUp 0.8s ease-out 0.3s both; }
.achievement { animation: achPop 0.4s ease-out both; }
.achievement:nth-child(2) { animation-delay: 0.1s; }
.achievement:nth-child(3) { animation-delay: 0.2s; }
.achievement:nth-child(4) { animation-delay: 0.3s; }
.achievement:nth-child(5) { animation-delay: 0.4s; }

/* ===== 按钮点击反馈 ===== */
.btn-primary:active, .btn-secondary:active { transform: scale(0.95); }
.option-btn:active { transform: scale(0.97); }

/* ===== 微信兼容 ===== */
body { -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

/* ===== 排行榜新条目 ===== */
.lb-item.lb-new { border-left: 3px solid var(--primary); }

/* MBTI Section */
.mbti-result { text-align: center; padding: 10px 0; }
.mbti-type { font-size: 2.5em; font-weight: bold; color: var(--primary); letter-spacing: 8px; margin-bottom: 5px; }
.mbti-name { font-size: 1.2em; color: var(--text-light); margin-bottom: 8px; }
.mbti-desc { font-size: 0.9em; color: var(--text-muted); margin-bottom: 15px; line-height: 1.5; }
.mbti-bars { display: flex; flex-direction: column; gap: 10px; }
.mbti-bar-row { display: flex; align-items: center; gap: 8px; }
.mbti-bar-label { width: 24px; font-weight: bold; font-size: 0.9em; text-align: center; }
.mbti-bar-label.active { color: var(--primary); }
.mbti-bar-label.inactive { color: var(--text-muted); }
.mbti-bar-container { flex: 1; height: 8px; background: var(--bg2); border-radius: 4px; position: relative; overflow: hidden; }
.mbti-bar-fill { height: 100%; border-radius: 4px; transition: width 0.8s ease; }
.mbti-bar-fill.left { background: linear-gradient(to right, var(--primary), var(--accent)); float: right; }
.mbti-bar-fill.right { background: linear-gradient(to left, #4a90d9, #7ab8f5); }
.mbti-bar-pct { width: 35px; font-size: 0.8em; color: var(--text-muted); text-align: center; }

/* Feedback Section */
.feedback-section {
  margin-top: 30px;
  padding: 20px;
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
}

.feedback-section h3 {
  color: var(--primary);
  margin-bottom: 8px;
}

.feedback-desc {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
}

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

.feedback-group label {
  display: block;
  color: var(--text);
  margin-bottom: 10px;
  font-weight: 500;
}

.rating-stars {
  display: flex;
  gap: 8px;
}

.rating-stars .star {
  font-size: 32px;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity 0.2s, transform 0.2s;
}

.rating-stars .star:hover,
.rating-stars .star.active {
  opacity: 1;
  transform: scale(1.1);
}

.feedback-buttons {
  display: flex;
  gap: 12px;
}

.feedback-btn {
  flex: 1;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.feedback-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--primary);
}

.feedback-btn.active {
  background: var(--primary);
  color: var(--bg);
  border-color: var(--primary);
}

#feedback-text {
  width: 100%;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

#feedback-text:focus {
  outline: none;
  border-color: var(--primary);
}

.feedback-success {
  color: var(--primary);
  text-align: center;
  margin-top: 12px;
  font-weight: 500;
}
.section-hint { background: linear-gradient(135deg, #667eea22, #764ba222); border-radius: 8px; padding: 8px 16px; margin-bottom: 12px; font-size: 13px; color: #a0aec0; text-align: center; border: 1px solid rgba(255,255,255,0.1); }

/* API Shortcut - 一键复制给AI */
.api-shortcut {
  margin-top: 24px;
  padding: 16px;
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  border: 1px dashed rgba(255,255,255,0.15);
}
.api-hint {
  font-size: 14px;
  color: #999;
  margin-bottom: 12px;
}
.copy-box {
  position: relative;
}
.copy-box pre {
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  color: #ccc;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 8px;
}
.btn-secondary {
  width: 100%;
  padding: 10px;
  background: rgba(0,255,136,0.15);
  color: #00ff88;
  border: 1px solid rgba(0,255,136,0.3);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover {
  background: rgba(0,255,136,0.25);
}
