:root {
  --c-ink: #4a2f1b;
  --c-card: rgba(255, 250, 240, 0.92);
  --c-accent: #ff8c42;
  --c-accent2: #ffb347;
  --c-green: #6fbf4a;
  --c-danger: #ff5b5b;
  --shadow: 0 10px 30px rgba(60, 35, 10, 0.25);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  background: #2b4a1e;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
  touch-action: none;
}
/* 暗角，提升质感 */
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(30, 20, 5, 0.35) 100%);
  z-index: 2;
}
/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 18px;
  pointer-events: none;
}
.hud-panel {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.stat {
  background: var(--c-card);
  border: 2px solid #f3e2c0;
  border-radius: 14px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
  text-align: center;
  min-width: 82px;
}
.stat .label { display: block; font-size: 12px; color: #a97c4f; letter-spacing: 1px; }
.stat .val { display: block; font-size: 26px; font-weight: 900; color: var(--c-ink); line-height: 1.1; }
.stat.combo .val { color: #e86a17; }
#combo.pop { animation: pop 0.25s ease; }
#hud-center {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  text-align: center;
}
.time-wrap {
  background: var(--c-card);
  border: 2px solid #f3e2c0;
  border-radius: 999px;
  padding: 8px 22px;
  box-shadow: var(--shadow);
  display: inline-block;
}
.time-wrap .label { font-size: 12px; color: #a97c4f; margin-right: 8px; letter-spacing: 1px; }
.time-wrap .val { font-size: 28px; font-weight: 900; color: var(--c-green); }
.time-wrap .unit { font-size: 14px; font-weight: 700; color: #a97c4f; }
.time-wrap.warn .val { color: var(--c-danger); animation: blink 0.6s infinite; }
.timebar { margin: 6px auto 0; width: 200px; height: 8px; background: rgba(255,250,240,0.55); border-radius: 999px; overflow: hidden; box-shadow: var(--shadow); }
#timebar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #7ec850, #4dae2f); border-radius: 999px; transition: width 0.2s linear, background 0.3s; }
.sound-btns { display: flex; gap: 8px; }
.sound-btns button {
  width: 44px; height: 44px;
  font-size: 22px;
  border: 2px solid #f3e2c0;
  border-radius: 12px;
  background: var(--c-card);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s, opacity 0.2s;
}
.sound-btns button:hover { transform: scale(1.06); }
.sound-btns button.off { opacity: 0.4; }
/* ---------- 飘字 ---------- */
#float-layer {
  position: fixed; inset: 0; z-index: 6;
  pointer-events: none; overflow: hidden;
}
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
  animation: floatUp 0.95s ease-out forwards;
}
.float-score { font-size: 30px; color: #fff; text-shadow: 0 2px 0 #4a2f1b, 0 3px 10px rgba(0,0,0,0.4); }
.float-combo { font-size: 26px; color: #ffe066; text-shadow: 0 2px 0 #c77a1a, 0 3px 10px rgba(0,0,0,0.4); }
.float-miss { font-size: 26px; color: #ff7a7a; text-shadow: 0 2px 0 #7a1a1a, 0 3px 10px rgba(0,0,0,0.4); }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.5); }
  15% { opacity: 1; transform: translate(-50%, -80%) scale(1.2); }
  100% { opacity: 0; transform: translate(-50%, -240%) scale(1); }
}
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.45); } 100% { transform: scale(1); } }
@keyframes blink { 50% { opacity: 0.4; } }
/* ---------- 倒计时 ---------- */
#countdown {
  position: fixed; inset: 0; z-index: 8;
  display: none;
  align-items: center; justify-content: center;
  pointer-events: none;
  font-size: 96px; font-weight: 900; color: #fff;
  text-shadow: 0 4px 0 #4a2f1b, 0 8px 24px rgba(0,0,0,0.5);
}
#countdown.show { display: flex; }
#countdown.pop { animation: cdpop 0.45s ease; }
@keyframes cdpop { 0% { transform: scale(0.4); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(35, 24, 8, 0.5);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.modal.show { display: flex; }
.card {
  background: linear-gradient(180deg, #fffaf0, #fdeeda);
  border: 3px solid #f3e2c0;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px 30px;
  max-width: 480px;
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  text-align: center;
  animation: cardIn 0.3s ease;
}
@keyframes cardIn { 0% { transform: translateY(24px) scale(0.95); opacity: 0; } 100% { transform: none; opacity: 1; } }
.card h1 { font-size: 30px; color: var(--c-ink); margin-bottom: 4px; }
.card .subtitle { font-size: 14px; color: #a97c4f; margin-bottom: 14px; }
.card .intro { font-size: 15px; line-height: 1.7; color: #6b4a2b; background: #fff6e6; border: 1px dashed #e8cf9a; border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.rules { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; }
.rules span { background: #fff; border: 1px solid #f0ddb8; border-radius: 999px; padding: 4px 12px; font-size: 13px; color: #6b4a2b; }
.best-line { font-size: 15px; color: #6b4a2b; margin-bottom: 18px; }
.best-line b { color: #e86a17; font-size: 20px; }
.btn {
  display: inline-block;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
  font-family: inherit;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(180deg, var(--c-accent2), var(--c-accent));
  border-radius: 999px;
  padding: 14px 40px;
  font-size: 20px;
  letter-spacing: 2px;
  box-shadow: 0 6px 0 #c96a24, 0 10px 20px rgba(200, 100, 30, 0.35);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #c96a24; }
.btn.secondary {
  background: linear-gradient(180deg, #f5efe2, #e6d7ba);
  color: var(--c-ink);
  box-shadow: 0 6px 0 #cbb98f, 0 10px 20px rgba(150, 120, 70, 0.25);
  font-size: 16px;
  padding: 12px 30px;
}
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 8px; }
.end-score { font-size: 64px; font-weight: 900; color: var(--c-ink); line-height: 1; margin: 6px 0; }
.end-score .unit { font-size: 20px; color: #a97c4f; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.stats-grid .cell { background: #fff; border: 1px solid #f0ddb8; border-radius: 12px; padding: 10px 6px; }
.stats-grid .cell .n { font-size: 22px; font-weight: 900; color: var(--c-ink); }
.stats-grid .cell .t { font-size: 12px; color: #a97c4f; }
.new-badge {
  display: inline-block; background: #ffd23e; color: #7a4a10;
  font-size: 13px; font-weight: 900; padding: 3px 10px; border-radius: 999px;
  margin-left: 8px; vertical-align: middle; animation: blink 0.8s infinite;
}
/* ---------- 赞助 ---------- */
.sponsor-btn { margin-top: 12px; }
.qr-box {
  width: 180px; height: 180px;
  margin: 4px auto 14px;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
  border: 2px dashed #d8b978;
  border-radius: 14px;
  color: #b08a5a;
  font-size: 14px;
}
/* ---------- 角色统计 ---------- */
.char-stats-title {
  font-size: 14px; font-weight: 900; color: var(--c-ink);
  letter-spacing: 1px; margin: 14px 0 8px;
}
.char-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.char-item {
  background: #fff;
  border: 1px solid #f0ddb8;
  border-radius: 12px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.char-item img {
  width: 46px; height: 46px;
  object-fit: cover;
  border-radius: 8px;
  background: #f3e2c0;
}
.char-item .char-name { font-size: 14px; font-weight: 900; color: var(--c-ink); }
.char-item .char-nums { font-size: 12px; color: #a97c4f; }
.char-item .char-nums b { color: #e86a17; font-size: 14px; }
/* ---------- 加载失败 ---------- */
#load-error {
  position: fixed; inset: 0; z-index: 20;
  display: none; align-items: center; justify-content: center;
  background: #2b4a1e; color: #fff; font-size: 18px; text-align: center; padding: 20px;
}
@media (max-width: 640px) {
  .stat { min-width: 54px; padding: 5px 8px; }
  .stat .val { font-size: 20px; }
  .stat-best { display: none; }
  #hud { padding: 8px 8px; }
  .hud-panel { gap: 6px; }
  #hud-center { top: 8px; }
  .time-wrap { padding: 5px 14px; }
  .time-wrap .val { font-size: 22px; }
  .timebar { width: 130px; }
  .sound-btns button { width: 38px; height: 38px; font-size: 18px; }
  .card { padding: 20px 18px; }
  .end-score { font-size: 48px; }
  .char-stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .char-item img { width: 40px; height: 40px; }
  .qr-box { width: 150px; height: 150px; }
}
