* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%; overflow: hidden; -webkit-tap-highlight-color: transparent;
  background: #ffffff;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #222;
}
body { display: flex; align-items: center; justify-content: center; touch-action: none; }

.game-container {
  position: relative; display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 20px 24px; width: 100%; max-width: 620px;
  background: #ffffff; border-radius: 24px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05), 0 10px 30px rgba(0,0,0,0.12), 0 30px 60px rgba(0,0,0,0.10), inset 0 1px 0 rgba(255,255,255,0.9);
}

.board-wrap {
  position: relative; padding: 18px; border-radius: 24px; background: #ffffff;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.08), inset 0 0 0 1px rgba(0,0,0,0.04), 0 4px 8px rgba(0,0,0,0.12), 0 12px 28px rgba(0,0,0,0.22), 0 30px 60px rgba(0,0,0,0.20), 0 60px 120px rgba(0,0,0,0.16);
  max-width: 100%; box-sizing: border-box;
}

canvas { border-radius: 12px; background: #ffffff; touch-action: none; display: block; max-width: 100%; height: auto; }
@media (min-width: 600px) { .board-wrap { padding: 22px; } }

/* HUD 优化 */
.hud { display: flex; gap: 15px; align-items: center; justify-content: space-between; width: 100%; font-size: 16px; user-select: none; padding: 0 10px; }
.hud-item b { color: #d4880a; font-size: 18px; transition: color 0.3s; }
.hud button { padding: 5px 12px; border: none; border-radius: 8px; background: #e8e8ef; color: #333; cursor: pointer; font-size: 13px; }

/* 步数警告 */
@keyframes pulse-red {
  0% { transform: scale(1); color: #e53935; }
  50% { transform: scale(1.15); color: #ff0000; text-shadow: 0 0 8px rgba(255,0,0,0.4); }
  100% { transform: scale(1); color: #e53935; }
}
.step-warning b {
  animation: pulse-red 1s infinite;
  display: inline-block;
}

.target-bar { width: 100%; text-align: center; font-size: 15px; color: #1a8f4a; background: rgba(92, 200, 143, 0.15); padding: 8px; border-radius: 8px; font-weight: bold; }

.tools { display: flex; flex-direction: column; gap: 6px; width: 100%; padding: 0 10px; align-items: stretch; box-sizing: border-box; }
.tools-row { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.tools-row-2 { gap: 6px; }
.tools-row-2 .tool-btn { flex: 1 1 0; justify-content: center; white-space: nowrap; }
.tool-btn { display: flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 12px; background: linear-gradient(135deg, #ffffff, #e8e8ef); color: #333; border: 1px solid rgba(0,0,0,0.12); box-shadow: 0 2px 6px rgba(0,0,0,0.12); font-size: 14px; font-weight: bold; cursor: pointer; transition: all 0.1s ease; white-space: nowrap; }
.tool-btn:active { transform: scale(0.92); }
.tool-btn:disabled { opacity: 0.4; filter: grayscale(1); cursor: not-allowed; transform: none; }
.tool-btn .icon { font-size: 16px; }
.tool-btn .badge { background: #ff5c5c; color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 10px; margin-left: 4px; box-shadow: inset 0 1px 3px rgba(0,0,0,0.3); }

/* 音乐与设置按钮样式 */
.music-btn { display: flex; align-items: center; justify-content: center; cursor: pointer; user-select: none; background: linear-gradient(135deg, #ffffff, #e8e8ef); border: 1px solid rgba(0,0,0,0.12); box-shadow: 0 2px 6px rgba(0,0,0,0.12); position: relative; padding: 8px; border-radius: 50%; width: 38px; height: 38px; transition: transform 0.1s; }
.music-btn:active { transform: scale(0.9); }
.music-btn .icon { font-size: 20px; line-height: 1; }
.top-right-group { position: absolute; top: 18px; right: 18px; z-index: 20; display: flex; gap: 10px; }

.music-btn.music-btn-main::after { content: ''; position: absolute; width: 70%; height: 3px; background: #c0392b; transform: rotate(-45deg); border-radius: 2px; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.music-btn.music-btn-main.music-off::after { opacity: 1; }
.music-btn.music-on .icon { animation: spin 4s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

#loading { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #888; pointer-events: none; z-index: 5; }
.overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(245, 245, 247, 0.96); backdrop-filter: blur(5px); display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 24px; z-index: 10; }

.title { font-size: 28px; margin-bottom: 15px; background: linear-gradient(90deg,#ff5c5c,#ffb13d,#3ecf7a,#5c8fff,#c85cff); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 800; }
.result-box { background: rgba(0,0,0,0.04); padding: 20px 30px; border-radius: 12px; margin-bottom: 25px; text-align: center; border: 1px solid rgba(0,0,0,0.08); width: 75%; box-sizing: border-box; }
.result-box p { font-size: 16px; margin: 8px 0; display: flex; justify-content: space-between; color: #333; align-items: center; }
.result-box b { color: #1a8f4a; font-size: 20px; }

/* 新纪录徽章样式 (位于分数左侧) */
.new-record-badge {
  margin-right: 8px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 92, 92, 0.08);
  border: 1px solid rgba(255, 92, 92, 0.35);
  color: #c0392b;
  font-size: 12px;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;       /* 不被右边的分数挤扁 */
  white-space: nowrap;  /* 三个字必须完整显示 */
  animation: pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes pop-in {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.btn-primary, .btn-secondary { width: 180px; padding: 14px 0; border: none; border-radius: 30px; font-size: 17px; font-weight: bold; cursor: pointer; margin-bottom: 12px; transition: transform 0.1s ease; }
.btn-primary { background: linear-gradient(135deg, #7c5cff, #5c8fff); color: #fff; box-shadow: 0 4px 15px rgba(124,92,255,0.35); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; transform: none; }
.btn-secondary { background: transparent; color: #666; border: 2px solid #ccc; }
.btn-primary:active, .btn-secondary:active { transform: scale(0.95); }

.history-list { width: 85%; max-height: 55vh; overflow-y: auto; background: rgba(0,0,0,0.04); border-radius: 12px; padding: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
/* 三列：关卡+模式名 | 星星 | 分数；后两列右对齐并贴右，整列看下去仍是齐的 */
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) 54px 52px; column-gap: 6px; align-items: center; padding: 12px 6px 12px 12px; background: rgba(255,255,255,0.9); border-radius: 8px; cursor: pointer; transition: background 0.2s; border: 1px solid rgba(0,0,0,0.06); }
.history-item:hover { background: #fff; }
.history-item span { font-size: 15px; }
.history-item .h-name { text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-stars { text-align: right; white-space: nowrap; }
.history-item .h-score { text-align: right; color: #1a8f4a; font-weight: bold; font-variant-numeric: tabular-nums; }
.history-item .h-score.fail { color: #c0392b !important; }
.history-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

/* 左上角 📮 邮箱：排在 🏠 下面，未读数用红角标贴在图标右上角 */
#main-menu #btn-mail { position: relative; }
#main-menu #btn-mail .mail-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  margin: 0;
  pointer-events: none;
}

/* 主页/设置等面板显示时，容器需要更多高度，避免内容溢出、按钮互相压住 */
body[data-view="menu"] .game-container {
  min-height: min(calc(100vh - 12px), 780px);
}

/* 所有的双按钮确认弹窗 */
#logout-confirm > div, #logout-confirm2 > div, #shuffle-confirm > div, #undo-confirm > div, #restart-confirm > div { display: flex; gap: 16px; justify-content: center; }
#logout-confirm .btn-primary, #logout-confirm2 .btn-primary, #shuffle-confirm .btn-primary, #undo-confirm .btn-primary, #restart-confirm .btn-primary { width: 130px; margin-bottom: 0; }
#duplicate-confirm > div { display: flex; gap: 16px; justify-content: center; }
#duplicate-confirm .btn-primary { width: 130px; margin-bottom: 0; }

/* 购买道具确认框：按钮比通用大按钮小一号 */
#buy-confirm > div { display: flex; gap: 14px; justify-content: center; }
#buy-confirm .btn-primary {
  width: 112px;
  padding: 9px 0;
  font-size: 14px;
  border-radius: 22px;
  margin-bottom: 0;
}

/* 滑块美化 */
input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; }
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 8px; cursor: pointer; background: #e8e8ef; border-radius: 4px; border: 1px solid rgba(0,0,0,0.05); }
input[type=range]::-webkit-slider-thumb { height: 20px; width: 20px; border-radius: 50%; background: #7c5cff; cursor: pointer; -webkit-appearance: none; margin-top: -7px; box-shadow: 0 2px 6px rgba(124,92,255,0.4); transition: transform 0.1s; }
input[type=range]::-webkit-slider-thumb:active { transform: scale(1.2); }
#input-custom-bgm, #input-rename, #input-name-new { transition: border-color 0.2s; }
#input-custom-bgm:focus, #input-rename:focus, #input-name-new:focus { border-color: #7c5cff !important; }

/* ================= 历史导入 / 播放列表 ================= */
.history-music-container {
  width: 85%; 
  background: rgba(0,0,0,0.03); border-radius: 12px; border: 1px solid rgba(0,0,0,0.08);
  padding: 8px; margin-bottom: 2px; box-sizing: border-box;
}

.history-music-list { width: 100%; max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }

.history-music-item-wrap { position: relative; overflow: hidden; border-radius: 6px; background: #fff; }

.history-music-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 10px; background: #fff; font-size: 14px; color: #333;
  position: relative; z-index: 2; transition: transform 0.2s ease;
  cursor: pointer; border: 1px solid rgba(0,0,0,0.05); border-radius: 6px;
}

.history-music-item.selected { background: rgba(124, 92, 255, 0.1); border-color: #7c5cff; }
.history-music-item.active { color: #7c5cff; font-weight: bold; border-color: #7c5cff; }

/* 左滑操作区 */
.swipe-actions {
  position: absolute; top: 0; right: 0; height: 100%;
  display: flex; z-index: 1; border-radius: 0 6px 6px 0; overflow: hidden;
}

.swipe-btn {
  height: 100%; width: 60px; border: none; color: white;
  font-size: 12px; font-weight: bold; cursor: pointer;
  display: flex; justify-content: center; align-items: center;
}
.swipe-btn.btn-rename { background: #e6a23c; }
.swipe-btn.btn-select { background: #5c8fff; }
.swipe-btn.btn-delete { background: #ff5c5c; }

/* 播放模式按钮的选中态 */
#btn-mode-seq.active, #btn-mode-shuf.active, #btn-mode-loop.active {
  border-color: #7c5cff;
  color: #7c5cff;
  font-weight: bold;
}

/* ================= 居中特效/提示浮层 ================= */
#center-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 16px 32px;
  border-radius: 30px;
  font-size: 26px;
  font-weight: 900;
  pointer-events: none;
  z-index: 99; /* 确保在 canvas 之上 */
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), inset 0 0 10px rgba(255,255,255,0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}
#center-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
/* 针对不同情况的颜色修饰 */
#center-banner.type-combo { background: linear-gradient(135deg, rgba(255, 159, 67, 0.95), rgba(255, 92, 92, 0.95)); }
#center-banner.type-bomb { background: linear-gradient(135deg, rgba(255, 92, 92, 0.95), rgba(200, 92, 255, 0.95)); }
#center-banner.type-rainbow { background: linear-gradient(135deg, rgba(92, 255, 143, 0.95), rgba(92, 143, 255, 0.95)); }

/* 连击横幅内的文字弹出动画（每次连击升级重放） */
#center-banner.show #center-banner-text {
  display: inline-block;
  animation: combo-pop 0.34s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes combo-pop {
  0% { transform: scale(0.5); opacity: 0.3; }
  60% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ================= 毕业结算面板专属样式 ================= */
#game-complete {
  background: radial-gradient(circle at 50% 30%, #fffdf5, #ffefd6 80%);
}

.complete-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
  animation: float-badge 3s ease-in-out infinite;
}

.complete-badge .icon {
  font-size: 64px;
  filter: drop-shadow(0 10px 15px rgba(255, 140, 0, 0.4));
}

.complete-badge .text {
  margin-top: 10px;
  font-size: 20px;
  font-weight: 900;
  background: linear-gradient(90deg, #ff8c00, #ff5c5c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 2px;
}

@keyframes float-badge {
  0% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

#game-complete #btn-goto-endless {
  background: linear-gradient(135deg, #ff8c00, #ff5c5c);
  color: #fff;
  box-shadow: 0 4px 15px rgba(255, 140, 0, 0.4);
  animation: pulse-endless 2s infinite;
  margin-bottom: 16px;
}

@keyframes pulse-endless {
  0% { box-shadow: 0 0 0 0 rgba(255, 140, 0, 0.6); }
  70% { box-shadow: 0 0 0 15px rgba(255, 140, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 140, 0, 0); }
}

#game-complete #complete-total-score {
  color: #ff5c5c;
  text-shadow: 0 2px 10px rgba(255, 92, 92, 0.2);
}

/* 窄屏下 HUD / 工具栏适配：工具栏固定两排（第一排 NEXT / 背包 / 音乐，第二排 提示 / 洗牌 / 撤回） */
@media (max-width: 520px) {
  .hud { flex-wrap: wrap; gap: 8px 12px; font-size: 14px; }
  .hud-item b { font-size: 16px; }
  .tools { gap: 5px; padding: 0 3px; }
  .tools-row { gap: 5px; }
  .preview-strip { padding: 3px 6px; gap: 4px; }
  .preview-strip::before { font-size: 9px; letter-spacing: 0.5px; }
  .preview-dot { width: 15px; height: 15px; border-radius: 4px; }
  .tool-btn { padding: 6px 8px; font-size: 12px; gap: 4px; }
  .tool-btn .badge { font-size: 10px; padding: 1px 5px; }
  .music-btn { width: 34px; height: 34px; }
  .music-btn .icon { font-size: 17px; }
}
@media (max-width: 340px) {
  .tool-btn .text { display: none; }
}

/* ================= 节奏关：节拍条 ================= */
.beat-bar {
  display: none;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0 14px;
  box-sizing: border-box;
  margin-top: 2px;
}
.beat-bar .beat-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #8a7fb5;
}
.beat-bar .beat-track {
  position: relative;
  flex: 1;
  height: 8px;
  border-radius: 6px;
  background: rgba(124, 92, 255, 0.14);
}
.beat-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0;
  border-radius: 6px;
  background: linear-gradient(90deg, #b3a4ff, #7c5cff);
}
.beat-dot {
  position: absolute;
  top: 50%;
  left: 0;
  width: 12px; height: 12px;
  margin-left: -6px; margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #7c5cff;
  box-sizing: border-box;
  transition: background 0.1s, border-color 0.1s;
}
.beat-dot.hot { background: #ff8c00; border-color: #ff8c00; }
.beat-dot.pulse { animation: beatPop 0.22s ease-out; }
@keyframes beatPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.9); }
  100% { transform: scale(1); }
}
.beat-hit {
  min-width: 58px;
  font-size: 11px;
  font-weight: 800;
  color: #ff8c00;
  text-align: right;
}
