/* ═══════════════════════════════════════════
   赛博木鱼 · Zen / Wabi-Sabi 主题
   ═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@300;400;700&family=Lora:ital,wght@0,400;0,500;0,600;1,400&display=swap');

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

:root {
  /* Warm Stone 900 */
  --bg-core: #1C1917;
  /* Amber 600 */
  --accent-wood: #D97706;
  /* Amber 700 */
  --accent-wood-dark: #B45309;
  /* Stone 100 */
  --text-main: #F5F5F4;
  /* Stone 400 */
  --text-dim: #A8A29E;
  /* 柔和的阴影 */
  --shadow-warm: rgba(0, 0, 0, 0.4);
  --glow-amber: rgba(217, 119, 6, 0.3);
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-core);
  /* 极其隐约的宣纸/木纹质感渐变 */
  background-image:
    radial-gradient(circle at 50% 50%, rgba(217, 119, 6, 0.03), transparent 70%);
  color: var(--text-main);
  font-family: 'Noto Serif SC', serif;
  letter-spacing: 1px;
}

/* 统一图标样式 */
.inline-icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.125em;
}

.hidden {
  display: none !important;
}

/* ─── 禅意淡入动画 (所有UI元素) ─── */
.zen-fade-in {
  animation: slowFadeIn 4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  opacity: 0;
}

@keyframes slowFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── Canvas 层 ─── */
#particle-canvas,
#float-canvas,
#milestone-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#particle-canvas {
  z-index: 1;
}

#float-canvas {
  z-index: 10;
}

#milestone-canvas {
  z-index: 100;
}

/* ─── 连接状态 (极简点缀) ─── */
#connection-status {
  position: fixed;
  top: 32px;
  left: 40px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'Noto Serif SC', serif;
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 2px;
}

.status-indicator {
  position: relative;
  width: 8px;
  height: 8px;
}

.status-dot {
  position: absolute;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all 1s ease;
}

.status-dot.connected {
  background: var(--accent-wood);
  box-shadow: 0 0 10px var(--glow-amber);
}

.status-dot.disconnected {
  background: #78350F;
  opacity: 0.5;
}

/* ─── 主容器 ─── */
.main-container {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 12vh;
  height: 100vh;
  pointer-events: none;
}

.main-container>* {
  pointer-events: auto;
}

/* ─── 禅意留白面板通用 ─── */
.zen-panel {
  background: rgba(28, 25, 23, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(217, 119, 6, 0.1);
  box-shadow: 0 10px 40px var(--shadow-warm);
}

/* ─── HUD 数据屏 (碑文感) ─── */
.hud-panel {
  text-align: center;
  margin-bottom: 5vh;
  padding: 32px 64px;
}

.hud-label {
  font-family: 'Noto Serif SC', serif;
  font-size: 15px;
  color: var(--text-dim);
  letter-spacing: 8px;
  /* 极宽的字间距增加禅意 */
  margin-bottom: 16px;
}

.total-number {
  font-family: 'Lora', serif;
  font-size: 96px;
  /* 更硕大的字体 */
  font-weight: 500;
  line-height: 1;
  color: var(--text-main);
  text-shadow: 0 4px 20px var(--shadow-warm);
  transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* 呼吸式跳动，而非霓虹爆闪 */
.total-number.flash {
  color: #FFFFFF;
  transform: scale(1.02);
  text-shadow: 0 0 30px var(--glow-amber);
}

.hud-footer {
  font-family: 'Noto Serif SC', serif;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 20px;
  letter-spacing: 4px;
  opacity: 0.6;
}

/* ─── 木鱼舞台 (图片实体) ─── */
/* 几何参考 muyu.html:
   - 舞台 460×420
   - 木鱼 360px 居中贴底
   - 木槌 165px, top:5 right:75, pivot 84% 89%
   - 静止 rotate(-10deg) 锤头抬起
   - 敲击 rotate(28deg) 锤头精确落在木鱼顶部 */
.muyu-stage {
  position: relative;
  width: 460px;
  height: 420px;
  margin-bottom: 2vh;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.muyu-img {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  width: 360px;
  height: 360px;
  object-fit: contain;
  transform-origin: center bottom;
  filter: drop-shadow(0 14px 20px rgba(80, 30, 0, 0.32));
  pointer-events: none;
}

/* 木槌：旋转轴=握把末端，静止时锤头抬起，敲击时精确落在木鱼顶部 */
.muyu-mallet {
  position: absolute;
  top: 5px;
  right: 75px;
  width: 165px;
  height: 165px;
  object-fit: contain;
  transform-origin: 84% 89%;
  /* 握把末端 = 旋转轴心 */
  transform: rotate(-10deg);
  /* 静止姿态：锤头抬起 */
  pointer-events: none;
  filter: drop-shadow(2px 5px 10px rgba(60, 20, 0, 0.38));
  z-index: 3;
}

/* 木鱼背后的微弱佛光 */
.muyu-aura {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 380px;
  height: 380px;
  transform: translate(-50%, -45%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217, 119, 6, 0.08) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
  z-index: 1;
}

/* ── 敲击动画 ── */

/* 普通敲击：快速下压 + 弹回 (模拟棒槌击中后木鱼的震颤) */
@keyframes knockImpact {
  0% {
    transform: translateX(-50%) scale(1, 1);
  }

  20% {
    transform: translateX(-50%) scale(1.07, 0.90) translateY(7px);
  }

  50% {
    transform: translateX(-50%) scale(0.96, 1.07) translateY(-3px);
  }

  75% {
    transform: translateX(-50%) scale(1.01, 0.99);
  }

  100% {
    transform: translateX(-50%) scale(1, 1);
  }
}

/* 木槌挥动 */
@keyframes malletSwing {
  0% {
    transform: rotate(-10deg);
  }

  /* 静止 */
  40% {
    transform: rotate(28deg);
  }

  /* 撞击：精确落在木鱼顶部 */
  58% {
    transform: rotate(15deg);
  }

  /* 弹起 */
  74% {
    transform: rotate(20deg);
  }

  /* 微颤 */
  100% {
    transform: rotate(-10deg);
  }

  /* 归位 */
}

/* 佛光一闪 */
@keyframes auraFlash {
  0% {
    opacity: 0;
    transform: translate(-50%, -45%) scale(0.8);
  }

  30% {
    opacity: 1;
    transform: translate(-50%, -45%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -45%) scale(1.2);
  }
}

/* 木槌独立触发（先于木鱼） */
.muyu-mallet.swing {
  animation: malletSwing 0.42s cubic-bezier(0.22, 0.61, 0.35, 1) forwards;
}

/* 木鱼震颤 + 佛光（延迟 168ms 后由 JS 触发） */
.muyu-stage.hit .muyu-img {
  animation: knockImpact 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards;
}

.muyu-stage.hit .muyu-aura {
  animation: auraFlash 0.6s ease forwards;
  background: radial-gradient(circle, rgba(217, 119, 6, 0.25) 0%, transparent 65%);
}

@keyframes bigKnockImpact {
  0% {
    transform: translateX(-50%) scale(1, 1);
  }

  15% {
    transform: translateX(-50%) scale(1.12, 0.85) translateY(10px);
  }

  40% {
    transform: translateX(-50%) scale(0.92, 1.12) translateY(-5px);
  }

  60% {
    transform: translateX(-50%) scale(1.04, 0.97);
  }

  80% {
    transform: translateX(-50%) scale(0.99, 1.02);
  }

  100% {
    transform: translateX(-50%) scale(1, 1);
  }
}

@keyframes auraPulse {
  0% {
    opacity: 0;
    transform: translate(-50%, -45%) scale(0.8);
  }

  20% {
    opacity: 1;
    transform: translate(-50%, -45%) scale(1.1);
  }

  50% {
    opacity: 0.8;
    transform: translate(-50%, -45%) scale(1.3);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -45%) scale(1.5);
  }
}

.muyu-stage.big-hit .muyu-img {
  animation: bigKnockImpact 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.muyu-stage.big-hit .muyu-aura {
  animation: auraPulse 1.2s ease forwards;
  background: radial-gradient(circle, rgba(217, 119, 6, 0.4) 0%, transparent 65%);
}

/* ─── 禅意提示/指令板 ─── */
.zen-inscription {
  text-align: center;
  cursor: pointer;
  padding: 16px 32px;
  position: relative;
  opacity: 0.7;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.zen-inscription:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.zen-text {
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 12px;
  color: #a3a3a3;
  letter-spacing: 0;
  background: rgba(0, 0, 0, 0.4);
  padding: 8px 12px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 12px;
}

.zen-text span {
  color: var(--accent-wood);
}

.zen-hint {
  font-family: 'Noto Serif SC', serif;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 6px;
  transition: color 0.4s ease;
}

.zen-inscription.copied .zen-hint {
  color: var(--accent-wood);
  animation: soft-pulse 1s ease;
}

@keyframes soft-pulse {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }

  100% {
    opacity: 1;
  }
}

/* ─── 排行榜 (碑文感) ─── */
.leaderboard {
  position: fixed;
  top: 18vh;
  right: 48px;
  z-index: 20;
  width: 250px;
  padding: 24px 20px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(28, 25, 23, 0.5) 0%, rgba(28, 25, 23, 0.2) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(217, 119, 6, 0.08);
  border-top: 1px solid rgba(217, 119, 6, 0.15);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.lb-header {
  margin-bottom: 20px;
  text-align: center;
  position: relative;
}

.lb-header::after {
  content: '';
  display: block;
  width: 50px;
  height: 1px;
  background: var(--accent-wood);
  margin: 16px auto 0;
  opacity: 0.3;
}

.lb-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 16px;
  font-weight: 400;
  color: var(--text-main);
  letter-spacing: 6px;
}

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

.lb-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed rgba(168, 162, 158, 0.1);
  transition: all 0.3s ease;
}

.lb-item:hover {
  transform: translateX(-4px);
  border-bottom-color: rgba(217, 119, 6, 0.3);
}

.lb-rank {
  font-family: 'Lora', serif;
  width: 28px;
  font-size: 14px;
  color: var(--text-dim);
  font-style: italic;
}

.lb-item:nth-child(1) .lb-rank {
  color: var(--accent-wood);
}

.lb-item:nth-child(2) .lb-rank {
  color: #E7E5E4;
}

.lb-item:nth-child(3) .lb-rank {
  color: var(--accent-wood-dark);
}

.lb-icon {
  font-size: 16px;
  margin-right: 12px;
  opacity: 0.8;
}

.lb-name {
  flex: 1;
  font-size: 14px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-total {
  font-family: 'Lora', serif;
  font-size: 14px;
  color: var(--text-dim);
}

/* ─── 音效开关 ─── */
.sound-toggle {
  position: fixed;
  bottom: 40px;
  right: 40px;
  z-index: 50;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid rgba(168, 162, 158, 0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s ease;
}

.sound-toggle svg {
  width: 20px;
  height: 20px;
  transition: stroke 0.4s ease;
}

.sound-toggle:hover {
  color: var(--text-main);
  border-color: rgba(217, 119, 6, 0.4);
}

.sound-toggle.on {
  color: var(--accent-wood);
  border-color: var(--accent-wood);
}

/* ─── 响应式 ─── */
@media (max-width: 1024px) {
  .leaderboard {
    width: 220px;
    right: 24px;
    padding: 20px 16px;
  }

  .total-number {
    font-size: 72px;
  }
}

@media (max-width: 768px) {
  .main-container {
    padding-top: 5vh;
    /* 给底部抽屉留出足够空间，防止遮挡代码 */
    padding-bottom: 45vh;
    height: auto;
    min-height: 100vh;
    justify-content: flex-start;
  }

  #connection-status {
    top: 16px;
    left: 16px;
    font-size: 12px;
  }

  .hud-panel {
    padding: 16px 20px;
    margin-bottom: 2vh;
  }

  .hud-label {
    letter-spacing: 6px;
    font-size: 12px;
  }

  .total-number {
    font-size: 48px;
  }

  .muyu-stage {
    /* 调整缩放并减小过度负边距 */
    transform: scale(0.55);
    margin-top: -60px;
    margin-bottom: -50px;
  }

  .zen-inscription {
    padding: 0 16px;
    max-width: 90vw;
    margin-top: -20px;
  }

  .zen-text {
    font-size: 10px;
    padding: 8px 10px;
    white-space: pre-wrap;
    word-break: break-all;
  }

  .leaderboard {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    transform: none;
    width: 100%;
    /* 控制底部抽屉高度，不要太高 */
    max-height: 38vh;
    border-radius: 16px 16px 0 0;
    border: none;
    border-top: 1px solid rgba(217, 119, 6, 0.2);
    /* 增强底部背景色以覆盖背景下方的瑕疵 */
    background: rgba(28, 25, 23, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 16px;
  }

  .lb-header {
    margin-bottom: 12px;
  }

  .lb-list {
    max-height: calc(38vh - 60px);
  }

  .sound-toggle {
    bottom: calc(38vh + 16px);
    right: 16px;
    width: 36px;
    height: 36px;
  }
}