/* style.css - 魔法传送门 v4.0 - 暗色魔法主题 */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #050210;
  min-height: 100vh;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  color: #e0e7ff;
}

.hidden { display: none !important; }

/* 头部 - 暗色玻璃态 */
#header {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; flex-direction: column;
  padding: 0; z-index: 10;
  background: rgba(15, 10, 30, 0.8);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(139, 92, 246, 0.15);
}
#header-row1 {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}
#title {
  font-size: 20px; font-weight: 700;
  background: linear-gradient(135deg, #a78bfa, #06b6d4);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  text-shadow: none;
}
#user-btn { min-width: 80px; }

/* Canvas */
#canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }

#hint {
  position: fixed; bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  left: 50%; transform: translateX(-50%);
  font-size: 15px; color: rgba(167, 139, 250, 0.9); text-align: center;
  pointer-events: none; transition: opacity 0.3s;
  white-space: nowrap;
  background: rgba(15, 10, 30, 0.85);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); padding: 10px 20px; border-radius: 20px;
  border: 1px solid rgba(139, 92, 246, 0.2);
}
#hint.pulse { animation: hintPulse 2s ease-in-out infinite; }
@keyframes hintPulse { 0%,100% { transform: translateX(-50%) scale(1); } 50% { transform: translateX(-50%) scale(1.05); } }

/* 结果界面 - 暗色玻璃态 */
#result-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(5, 2, 16, 0.85);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  z-index: 20; animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#score-display {
  display: flex; align-items: baseline; justify-content: center;
  animation: bounceIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  filter: drop-shadow(0 4px 20px rgba(139, 92, 246, 0.3));
}
@keyframes bounceIn {
  0% { transform: scale(0.3) rotate(-5deg); opacity: 0; }
  50% { transform: scale(1.08) rotate(2deg); }
  70% { transform: scale(0.92); }
  100% { transform: scale(1); opacity: 1; }
}

#score-number {
  font-size: 80px; font-weight: 900; line-height: 1;
  background: linear-gradient(135deg, #a78bfa, #06b6d4);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
#score-unit { font-size: 36px; font-weight: 700; color: #a78bfa; margin-left: 6px; opacity: 0.9; }

#grade-text {
  font-size: 24px; margin-top: 12px; font-weight: 600;
  animation: slideUp 0.5s ease 0.3s both;
  text-shadow: 0 0 20px currentColor;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

#result-canvas {
  margin: 20px 0; border-radius: 16px; max-width: 280px; max-height: 280px;
  box-shadow: 0 8px 32px rgba(139, 92, 246, 0.2);
  border: 2px solid rgba(139, 92, 246, 0.3);
  animation: slideUp 0.5s ease 0.4s both;
}

#result-actions { display: flex; gap: 14px; margin-top: 12px; animation: slideUp 0.5s ease 0.5s both; }

#best-score-display {
  margin-top: 20px; font-size: 14px; color: rgba(167, 139, 250, 0.8); font-weight: 500;
  background: rgba(139, 92, 246, 0.1); padding: 8px 16px; border-radius: 20px;
  border: 1px solid rgba(139, 92, 246, 0.2);
  animation: slideUp 0.5s ease 0.6s both;
}

/* 按钮 - 魔法风格 */
.btn {
  padding: 14px 32px; font-size: 16px; font-weight: 600;
  border: 1px solid rgba(139, 92, 246, 0.3);
  background: rgba(139, 92, 246, 0.15); color: #e0e7ff;
  border-radius: 30px; cursor: pointer;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  outline: none; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.15);
  backdrop-filter: blur(8px);
}
.btn:hover { background: rgba(139, 92, 246, 0.25); transform: translateY(-2px); box-shadow: 0 6px 24px rgba(139, 92, 246, 0.25); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn-green {
  background: rgba(34, 197, 94, 0.2); border-color: rgba(34, 197, 94, 0.3);
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.15);
}
.btn-green:hover { background: rgba(34, 197, 94, 0.3); }
.btn-small { padding: 10px 20px; font-size: 14px; }

/* 排行榜入口 */
#leaderboard-toggle {
  position: fixed; bottom: max(24px, calc(24px + env(safe-area-inset-bottom)));
  right: max(24px, calc(24px + env(safe-area-inset-right))); z-index: 15;
  animation: float 3s ease-in-out infinite;
}
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* 弹窗 - 暗色 */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
.modal-content {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: rgba(15, 10, 30, 0.95); backdrop-filter: blur(20px);
  border-radius: 20px; width: 90%; max-width: 420px; max-height: 75vh;
  overflow-y: auto; padding: 24px;
  box-shadow: 0 24px 80px rgba(139, 92, 246, 0.2);
  border: 1px solid rgba(139, 92, 246, 0.2);
  animation: modalSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes modalSlideIn { from { opacity: 0; transform: translate(-50%,-45%); } to { opacity: 1; transform: translate(-50%,-50%); } }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 {
  font-size: 22px; font-weight: 700;
  background: linear-gradient(135deg, #a78bfa, #06b6d4);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.modal-close {
  width: 36px; height: 36px; border: 1px solid rgba(139,92,246,0.2);
  background: rgba(139,92,246,0.1); border-radius: 50%; font-size: 18px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; color: #a78bfa;
}
.modal-close:hover { background: rgba(139,92,246,0.2); transform: rotate(90deg); }

/* 排行榜列表 */
.lb-item {
  display: flex; align-items: center; padding: 12px 8px;
  border-bottom: 1px solid rgba(139,92,246,0.1);
  transition: all 0.2s; border-radius: 8px;
}
.lb-item:hover { background: rgba(139,92,246,0.08); transform: translateX(4px); }
.lb-item.lb-me {
  background: rgba(139,92,246,0.15); border: 1px solid rgba(139,92,246,0.3); margin: 4px 0;
}
.lb-rank { width: 36px; font-size: 17px; font-weight: 800; color: #666; text-align: center; }
.lb-rank.top1 { color: #fbbf24; text-shadow: 0 0 12px rgba(251,191,36,0.5); font-size: 20px; }
.lb-rank.top2 { color: #C0C0C0; text-shadow: 0 0 12px rgba(192,192,192,0.4); font-size: 19px; }
.lb-rank.top3 { color: #CD7F32; text-shadow: 0 0 12px rgba(205,127,50,0.4); font-size: 18px; }
.lb-avatar {
  width: 40px; height: 40px; border-radius: 50%; margin: 0 12px;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  object-fit: cover; border: 2px solid rgba(139,92,246,0.3);
}
.lb-name { flex: 1; font-size: 15px; font-weight: 500; color: #e0e7ff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score {
  font-size: 20px; font-weight: 800;
  background: linear-gradient(135deg, #a78bfa, #06b6d4);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* 撒花 */
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg) scale(0.5); opacity: 0; }
}

/* 响应式 */
@media (max-width: 380px) {
  #score-number { font-size: 56px; }
  #score-unit { font-size: 28px; }
  #grade-text { font-size: 20px; }
  .btn { padding: 12px 24px; font-size: 15px; }
  #result-canvas { max-width: 240px; max-height: 240px; }
}

/* 滚动条 */
.modal-content::-webkit-scrollbar { width: 6px; }
.modal-content::-webkit-scrollbar-track { background: rgba(139,92,246,0.05); border-radius: 10px; }
.modal-content::-webkit-scrollbar-thumb { background: linear-gradient(135deg, #8b5cf6, #06b6d4); border-radius: 10px; }

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* 横屏提示 */
@media (orientation: landscape) and (max-height: 500px) {
  #hint { bottom: 20px; font-size: 13px; padding: 8px 16px; }

  #score-number { font-size: 56px; }
  #result-canvas { max-width: 200px; max-height: 200px; }
  #grade-text { font-size: 18px; }
  .btn { padding: 10px 24px; font-size: 14px; }
}

/* 分享弹窗 */
#share-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
#share-modal.hidden { display: none !important; }
.share-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.share-panel {
  position: relative; z-index: 1;
  background: rgba(15, 10, 30, 0.97); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 20px 20px 0 0; width: 100%; max-width: 420px;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(139, 92, 246, 0.2);
  animation: shareSlideUp 0.3s ease;
}
@keyframes shareSlideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.share-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; font-size: 18px; font-weight: 600; color: #e0e7ff;
}
.share-close {
  width: 32px; height: 32px; border: 1px solid rgba(139,92,246,0.2);
  background: rgba(139,92,246,0.1); border-radius: 50%; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: #a78bfa; transition: all 0.2s;
}
.share-close:hover { background: rgba(139,92,246,0.2); }
.share-preview-wrap {
  display: flex; justify-content: center; margin-bottom: 16px;
}
#share-preview-canvas {
  border-radius: 12px; border: 1px solid rgba(139,92,246,0.2);
  box-shadow: 0 4px 20px rgba(139,92,246,0.15);
}
.share-actions { display: flex; gap: 10px; }
.share-btn {
  flex: 1; padding: 14px 8px; font-size: 14px; font-weight: 600;
  border: 1px solid rgba(139,92,246,0.3); background: rgba(139,92,246,0.1);
  color: #e0e7ff; border-radius: 14px; cursor: pointer;
  transition: all 0.2s; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.share-btn:active { transform: scale(0.96); }
.share-btn-primary { background: rgba(139,92,246,0.25); border-color: rgba(139,92,246,0.5); }
.share-toast { display: block;
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(139,92,246,0.9); color: #fff; padding: 10px 20px;
  border-radius: 20px; font-size: 14px; font-weight: 500;
  animation: fadeIn 0.2s ease; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(139,92,246,0.3);
}

.share-toast.hidden { display: none !important; }

/* 排名显示 */
.rank-line { font-size: 16px; font-weight: 700; color: #e0e7ff; }
.best-line { font-size: 13px; color: rgba(167,139,250,0.7); margin-top: 4px; }

/* ===== 形状选择器 ===== */
#shape-selector {
  display: flex; gap: 6px; justify-content: center; align-items: center;
  padding: 4px 16px 8px;
  transition: opacity 0.3s;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.shape-card {
  display: flex; align-items: center; gap: 3px;
  padding: 3px 10px; border-radius: 14px; border: 1.5px solid rgba(139,92,246,0.15);
  background: transparent;
  color: #a78bfa; cursor: pointer; transition: all 0.2s;
  font-family: inherit; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.shape-card:active { transform: scale(0.95); }
.shape-card.active { border-color: #8b5cf6; background: rgba(139,92,246,0.15); color: #e0e7ff; box-shadow: 0 0 8px rgba(139,92,246,0.2); }
.shape-emoji { font-size: 14px; line-height: 1; }
.shape-label { font-size: 12px; }
.shape-name { display: none; }
.shape-diff { display: none; }
.diff-1 { background: rgba(34,197,94,0.2); color: #4ade80; }
.diff-2 { background: rgba(251,191,36,0.2); color: #fbbf24; }
.diff-3 { background: rgba(239,68,68,0.2); color: #f87171; }

/* ===== 排行榜形状Tab ===== */
.lb-tabs { display: flex; gap: 6px; padding: 8px 0 12px; justify-content: center; flex-wrap: wrap; }
.lb-tab {
  padding: 4px 12px; border-radius: 8px; border: 1px solid rgba(139,92,246,0.3);
  background: transparent; color: #a78bfa; font-size: 13px; cursor: pointer;
  transition: all 0.2s; font-family: inherit;
}
.lb-tab.active { background: rgba(139,92,246,0.2); border-color: #8b5cf6; color: #e0e7ff; }
.lb-tab:hover { border-color: #8b5cf6; }

/* 排名显示 */
.rank-line { font-size: 16px; font-weight: 700; color: #e0e7ff; }
.best-line { font-size: 13px; color: rgba(167,139,250,0.7); margin-top: 4px; }

/* 排行榜形状筛选tabs */
.lb-tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 4px; }
.lb-tab {
  padding: 6px 14px; font-size: 13px; font-weight: 600;
  border: 1px solid rgba(139,92,246,0.2); background: rgba(139,92,246,0.05);
  color: #a78bfa; border-radius: 16px; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.lb-tab:active { transform: scale(0.95); }
.lb-tab.active { background: rgba(139,92,246,0.2); border-color: #8b5cf6; color: #e0e7ff; box-shadow: 0 0 8px rgba(139,92,246,0.3); }
