/* ==============================================================
   音乐盒 · 游戏专属样式
   选择器统一以 .g-musicbox 前缀限定
   ============================================================== */

.g-musicbox {
  gap: 10px;
  --mb-star: clamp(46px, 13.2vw, 60px);
}

/* ------------------------------ 顶部 ------------------------------ */

.g-musicbox .mb-mute {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
  background: linear-gradient(160deg, rgba(121, 184, 255, 0.16), rgba(255, 255, 255, 0.03));
  color: #cfe6ff;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.g-musicbox .mb-mute.is-off {
  color: var(--faint);
  border-color: var(--line);
  background: var(--surface);
}

.g-musicbox .mb-hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: none;
}
.g-musicbox .mb-hud-i {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  padding: 5px 3px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.g-musicbox .mb-k { font-size: 10px; color: var(--faint); letter-spacing: 0.03em; }
.g-musicbox .mb-v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------ 夜空舞台 ------------------------------ */

.g-musicbox .mb-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(123, 170, 235, 0.2);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(121, 184, 255, 0.16), transparent 55%),
    radial-gradient(80% 60% at 20% 90%, rgba(84, 60, 160, 0.22), transparent 70%),
    radial-gradient(70% 50% at 85% 85%, rgba(40, 90, 160, 0.2), transparent 70%),
    linear-gradient(180deg, #0a1730 0%, #0a1428 55%, #070e1c 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 24px 54px -32px rgba(0, 0, 0, 0.85);
}
.g-musicbox .mb-dot {
  position: absolute;
  border-radius: 50%;
  background: #dcecff;
  opacity: 0.7;
  pointer-events: none;
  animation: mbTwinkle 3.2s ease-in-out infinite;
}

/* 月亮 / 漂浮音符 */
.g-musicbox .mb-moon {
  position: absolute;
  z-index: 1;
  top: 6%;
  right: 7%;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, rgba(224, 240, 255, 0.9), rgba(150, 196, 245, 0.35) 52%, rgba(120, 160, 220, 0) 72%);
  filter: blur(1px);
  opacity: 0.75;
  pointer-events: none;
}
.g-musicbox .mb-float {
  position: absolute;
  z-index: 1;
  color: rgba(190, 220, 255, 0.5);
  font-size: 16px;
  font-style: normal;
  pointer-events: none;
  animation: mbFloat 9s ease-in-out infinite;
  text-shadow: 0 0 12px rgba(121, 184, 255, 0.35);
}
@keyframes mbFloat {
  0%, 100% { transform: translateY(8px) rotate(-4deg); opacity: 0.18; }
  50% { transform: translateY(-14px) rotate(5deg); opacity: 0.55; }
}

/* 星星音块 */
.g-musicbox .mb-grid {
  position: relative;
  z-index: 2;
  flex: none;
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, var(--mb-star));
  gap: 10px 16px;
  justify-content: center;
}
.g-musicbox .mb-star {
  position: relative;
  width: var(--mb-star);
  height: var(--mb-star);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
  transition: transform 0.16s ease, filter 0.16s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.g-musicbox .mb-star::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  background:
    radial-gradient(circle at 38% 28%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 42%),
    linear-gradient(160deg, #e8f2ff, #a9cdf7 55%, #7fb3ea);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
  transition: background 0.16s ease;
}
.g-musicbox .mb-star:active { transform: scale(0.94); }
.g-musicbox .mb-star-face {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 6%;
  line-height: 1;
}
.g-musicbox .mb-star-n {
  font-size: calc(var(--mb-star) * 0.3);
  font-weight: 800;
  color: #16304f;
  letter-spacing: -0.02em;
}
.g-musicbox .mb-star-o {
  font-size: calc(var(--mb-star) * 0.16);
  font-weight: 700;
  color: rgba(22, 48, 79, 0.55);
  margin-top: 1px;
}
.g-musicbox .mb-star.lit {
  transform: scale(1.1);
  filter: drop-shadow(0 0 16px rgba(255, 240, 190, 0.95));
}
.g-musicbox .mb-star.lit::before {
  background:
    radial-gradient(circle at 38% 28%, #ffffff, rgba(255, 255, 255, 0) 46%),
    linear-gradient(160deg, #fff8dd, #f2d16b 60%, #e0b23f);
}
.g-musicbox .mb-star.lit .mb-star-n,
.g-musicbox .mb-star.lit .mb-star-o { color: #4a3510; }

/* 录音角标 */
.g-musicbox .mb-rec-tag {
  position: absolute;
  z-index: 4;
  top: 10px;
  right: 12px;
  display: none;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(6, 12, 22, 0.72);
  border: 1px solid rgba(255, 110, 110, 0.45);
  color: #ffb3b3;
  font-size: 10px;
  letter-spacing: 0.05em;
}
.g-musicbox .mb-rec-tag i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ff6b6b;
  animation: mbPulse 1s ease-in-out infinite;
}
.g-musicbox .mb-stage.recording .mb-rec-tag { display: flex; }

/* 录音序列 */
.g-musicbox .mb-seq {
  position: relative;
  z-index: 2;
  flex: none;
  margin: 8px 12px 0;
  min-height: 22px;
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 10.5px;
  color: rgba(210, 230, 255, 0.45);
  white-space: nowrap;
}
.g-musicbox .mb-seq-i {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(121, 184, 255, 0.14);
  border: 1px solid rgba(121, 184, 255, 0.28);
  color: #cfe6ff;
  font-variant-numeric: tabular-nums;
}
.g-musicbox .mb-seq-i.last {
  background: rgba(242, 209, 107, 0.22);
  border-color: rgba(242, 209, 107, 0.55);
  color: #ffe9a6;
}
.g-musicbox .mb-seq.empty { font-size: 10.5px; }

/* 八音盒底座 */
.g-musicbox .mb-box {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 14px;
}
.g-musicbox .mb-box-disc {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 2px solid rgba(242, 209, 107, 0.38);
  background:
    repeating-conic-gradient(from 0deg, rgba(242, 209, 107, 0.42) 0 5deg, rgba(242, 209, 107, 0.08) 5deg 11deg),
    radial-gradient(circle at 50% 40%, #24405f, #0d1a2c 68%, #0a1422);
  box-shadow: 0 0 22px rgba(121, 184, 255, 0.18), inset 0 0 18px rgba(0, 0, 0, 0.6);
  animation: mbSpin 18s linear infinite;
}
.g-musicbox .mb-box-ring {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1px dashed rgba(242, 209, 107, 0.45);
}
.g-musicbox .mb-box-core {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffe9a6;
  font-size: 22px;
  text-shadow: 0 0 10px rgba(242, 209, 107, 0.8);
}
.g-musicbox .mb-box.spinning .mb-box-disc { animation-duration: 3.6s; }
.g-musicbox .mb-box-base {
  width: 122px;
  height: 20px;
  margin-top: -6px;
  clip-path: polygon(10% 0, 90% 0, 100% 100%, 0 100%);
  background: linear-gradient(180deg, #3a5478, #1a2b44 55%, #0e1a2b);
  border-top: 1px solid rgba(242, 209, 107, 0.32);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
}
.g-musicbox .mb-box-shadow {
  width: 138px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.5), transparent 70%);
  margin-top: -4px;
}

/* 星尘 */
.g-musicbox .mb-dust {
  position: absolute;
  z-index: 3;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff, #f2d16b);
  pointer-events: none;
  animation: mbDust 0.8s ease-out forwards;
}

/* ------------------------------ 操作 ------------------------------ */

.g-musicbox .mb-ctrl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: none;
}
.g-musicbox .mb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 46px;
  padding: 0 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--dim);
  font-size: 12.5px;
  font-weight: 600;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, color 0.15s;
  touch-action: manipulation;
}
.g-musicbox .mb-btn:active { transform: scale(0.96); background: var(--surface-2); }
.g-musicbox .mb-btn.is-disabled { opacity: 0.38; pointer-events: none; }
.g-musicbox .mb-btn.is-playing,
.g-musicbox .mb-btn.is-recording {
  color: #ffe9a6;
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  background: linear-gradient(160deg, rgba(242, 209, 107, 0.16), rgba(121, 184, 255, 0.08));
}
.g-musicbox .mb-ctrl2 .mb-btn { min-height: 40px; font-size: 12px; }
.g-musicbox .mb-lib-n {
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(121, 184, 255, 0.18);
  color: #cfe6ff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ------------------------------ 底部 sheet ------------------------------ */

.mb-sheet {
  position: fixed;
  inset: 0;
  z-index: 88;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.mb-sheet-back {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 14, 0.56);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: mbFade 0.18s ease both;
}
.mb-sheet-panel {
  position: relative;
  width: min(100%, 560px);
  max-height: 76vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #101d31, #0a1320 70%);
  border: 1px solid var(--line-2);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  padding: 14px 14px calc(14px + var(--safe-b));
  box-shadow: 0 -24px 60px -20px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: mbUp 0.24s cubic-bezier(0.22, 0.9, 0.3, 1) both;
}
.mb-sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.mb-sheet-t { font-size: 16px; font-weight: 800; }
.mb-sheet-close {
  margin-left: auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: var(--dim);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  flex: none;
}
.mb-sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 10px 2px 4px;
}
.mb-sec-t { font-size: 11.5px; color: var(--dim); margin: 4px 2px 10px; letter-spacing: 0.03em; }

.mb-mel-row,
.mb-song-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  margin-bottom: 8px;
}
.mb-mel-row.empty { opacity: 0.62; border-style: dashed; background: rgba(255, 255, 255, 0.02); }
.mb-mel-tag {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #ffe9a6;
  background: linear-gradient(160deg, rgba(242, 209, 107, 0.18), rgba(121, 184, 255, 0.1));
  border: 1px solid rgba(242, 209, 107, 0.3);
}
.mb-mel-mid, .mb-song-mid { flex: 1; min-width: 0; }
.mb-mel-n, .mb-song-n { font-size: 13px; font-weight: 600; }
.mb-mel-desc, .mb-song-desc {
  font-size: 10.5px;
  color: var(--faint);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mb-mel-btns { display: flex; gap: 6px; flex: none; }
.mb-mel-btns .btn { flex: none; }

/* ------------------------------ 动画 ------------------------------ */

@keyframes mbTwinkle {
  0%, 100% { opacity: 0.28; transform: scale(0.9); }
  50% { opacity: 0.9; transform: scale(1.15); }
}
@keyframes mbSpin { to { transform: rotate(360deg); } }
@keyframes mbPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }
@keyframes mbDust {
  to { transform: translate(var(--dx, 0), -44px) scale(0.35); opacity: 0; }
}
@keyframes mbFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mbUp {
  from { transform: translateY(18px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

/* ------------------------------ 适配 ------------------------------ */

@media (max-height: 710px) {
  .g-musicbox { gap: 8px; --mb-star: clamp(42px, 12vw, 52px); }
  .g-musicbox .mb-ctrl2 .mb-btn { min-height: 38px; }
  .g-musicbox .mb-btn { min-height: 42px; }
  .g-musicbox .mb-hud-i { min-height: 28px; }
  .g-musicbox .mb-box { min-height: 88px; }
  .g-musicbox .mb-box-disc { width: 82px; height: 82px; }
  .g-musicbox .mb-box-base { width: 102px; height: 16px; }
  .mb-sheet-panel { max-height: 84vh; }
}

@media (max-width: 365px) {
  .g-musicbox .mb-btn { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .g-musicbox .mb-dot,
  .g-musicbox .mb-box-disc,
  .g-musicbox .mb-rec-tag i { animation: none; }
  .mb-sheet-back, .mb-sheet-panel { animation: none; }
}
