/* ==========================================================================
   军训 · 表演方阵 | 军体拳跟拍挑战  —— 样式表
   设计基调：军营迷彩 + 红色战旗 + 草地训练场
   ========================================================================== */

/* ---------- 0. 变量与基础 ---------- */
:root {
  --ink: #07110b;
  --ink-2: #0d1a12;
  --panel: rgba(9, 22, 14, 0.88);
  --panel-line: rgba(126, 200, 152, 0.28);
  --grass: #3f6b3a;
  --grass-dark: #2a4a28;
  --sand: #c9b48a;
  --khaki: #8a7b4f;
  --accent: #ffc53d;
  --red: #e0483a;
  --red-dark: #a52a1f;
  --green: #5fd48a;
  --text: #eaf3ea;
  --text-dim: #a9c0ac;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC",
    system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 50% -15%, #24402c 0%, transparent 60%),
    repeating-linear-gradient(135deg, #0b1610 0 22px, #0d1a12 22px 44px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 1. 舞台容器 ---------- */
.stage {
  position: relative;
  width: min(1120px, 96vw, calc(94vh * 1.6923));
  aspect-ratio: 880 / 520;
  border-radius: 22px;
  overflow: hidden;
  background: #0a1410;
  border: 1px solid rgba(150, 220, 170, 0.18);
  box-shadow: var(--shadow), 0 0 0 6px rgba(0, 0, 0, 0.25);
  isolation: isolate;
  user-select: none;
}

canvas#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- 2. HUD ---------- */
.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 16px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

.is-playing .hud {
  opacity: 1;
  transform: translateY(0);
}

.hud-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-right {
  pointer-events: auto;
}

.pill {
  background: rgba(6, 16, 10, 0.62);
  border: 1px solid rgba(150, 220, 170, 0.22);
  border-radius: 999px;
  padding: 6px 12px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  backdrop-filter: blur(6px);
}

.pill-label {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.pill-value {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hud-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.score-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 26px 8px;
  background: linear-gradient(180deg, rgba(8, 20, 12, 0.8), rgba(8, 20, 12, 0.35));
  border: 1px solid rgba(255, 197, 61, 0.25);
  border-radius: 0 0 18px 18px;
  backdrop-filter: blur(6px);
}

.score-label {
  font-size: 10px;
  letter-spacing: 4px;
  color: var(--text-dim);
}

.score-value {
  font-size: clamp(24px, 3.4vw, 40px);
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
  letter-spacing: 1px;
}

.score-value.is-bump {
  animation: bump 0.3s ease;
}

@keyframes bump {
  0% { transform: scale(1); color: #fff; }
  45% { transform: scale(1.22); color: var(--accent); }
  100% { transform: scale(1); color: #fff; }
}

.combo {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
  transition: color 0.2s;
}

.combo.is-hot {
  color: #ff8a5c;
  text-shadow: 0 0 12px rgba(255, 110, 60, 0.8);
}

.combo.is-bump {
  animation: bump 0.3s ease;
}

.hearts {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 4px 8px;
  background: rgba(6, 16, 10, 0.55);
  border-radius: 999px;
  border: 1px solid rgba(150, 220, 170, 0.2);
}

.heart {
  width: 16px;
  height: 16px;
  background: var(--red);
  clip-path: polygon(50% 100%, 0 45%, 8% 20%, 30% 12%, 50% 24%, 70% 12%, 92% 20%, 100% 45%);
  transition: transform 0.2s, opacity 0.4s, filter 0.4s;
  filter: drop-shadow(0 0 6px rgba(224, 72, 58, 0.7));
}

.heart.is-lost {
  opacity: 0.22;
  filter: grayscale(1);
  transform: scale(0.82);
}

.heart.is-hit {
  animation: heartHit 0.45s ease;
}

@keyframes heartHit {
  0% { transform: scale(1.5) rotate(-12deg); }
  100% { transform: scale(0.82); }
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(150, 220, 170, 0.25);
  background: rgba(6, 16, 10, 0.6);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 197, 61, 0.18);
  transform: translateY(-1px);
}

/* ---------- 3. 节拍进度条 ---------- */
.timebar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 5px;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.3s;
}

.is-playing .timebar {
  opacity: 1;
}

.timebar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #7ff0a8, var(--accent) 65%, var(--red));
  box-shadow: 0 0 14px rgba(255, 197, 61, 0.75);
  border-radius: 0 3px 3px 0;
}

/* ---------- 4. 浮层与面板 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 3.2%;
  background:
    radial-gradient(60% 60% at 50% 30%, rgba(20, 44, 28, 0.72), rgba(3, 8, 5, 0.92));
  backdrop-filter: blur(7px);
  z-index: 5;
  overflow: auto;
}

.overlay.is-active {
  display: flex;
  animation: fadeIn 0.28s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.panel {
  width: min(100%, 720px);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  padding: clamp(16px, 2.4vw, 30px);
  animation: panelIn 0.36s cubic-bezier(0.2, 0.9, 0.25, 1.1);
  position: relative;
  max-height: 100%;
  overflow: auto;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(22px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.panel-small { width: min(100%, 460px); text-align: center; }
.panel-end { width: min(100%, 760px); }
.panel-board { width: min(100%, 560px); }

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 5px;
  color: var(--accent);
  text-transform: uppercase;
}

.title {
  margin: 0 0 10px;
  font-size: clamp(24px, 3.6vw, 42px);
  letter-spacing: 2px;
  line-height: 1.15;
  background: linear-gradient(100deg, #fff 20%, #ffe6a8 55%, #8fe3ab 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-dot { color: var(--red); -webkit-text-fill-color: var(--red); }

.h2 {
  margin: 0 0 8px;
  font-size: clamp(20px, 2.6vw, 30px);
  letter-spacing: 1px;
}

.h3 {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--text-dim);
}

.subtitle {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: clamp(12.5px, 1.35vw, 15px);
  line-height: 1.75;
}

.subtitle b { color: var(--accent); }

/* ---------- 5. WASD 演示 ---------- */
.keys-demo {
  display: flex;
  gap: 10px;
  margin: 4px 0 18px;
}

.key {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 12px;
  background: linear-gradient(180deg, #23392a, #16261c);
  border: 1px solid rgba(150, 220, 170, 0.35);
  box-shadow: 0 5px 0 #0c1710, 0 8px 18px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  animation: keyFloat 2.4s ease-in-out infinite;
}

.key i {
  position: absolute;
  bottom: -18px;
  font-size: 11px;
  font-style: normal;
  color: var(--text-dim);
}

.key:nth-child(2) { animation-delay: 0.2s; }
.key:nth-child(3) { animation-delay: 0.4s; }
.key:nth-child(4) { animation-delay: 0.6s; }

@keyframes keyFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* ---------- 6. 难度卡片 ---------- */
.diff-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 26px 0 20px;
}

.diff-card {
  position: relative;
  text-align: left;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(150, 220, 170, 0.22);
  background: linear-gradient(180deg, rgba(30, 52, 37, 0.7), rgba(12, 24, 16, 0.7));
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.18s, border-color 0.22s, box-shadow 0.22s, background 0.22s;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.diff-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 197, 61, 0.5);
}

.diff-card.is-picked {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(90, 72, 20, 0.55), rgba(20, 30, 18, 0.8));
  box-shadow: 0 0 0 1px rgba(255, 197, 61, 0.5), 0 10px 28px rgba(255, 197, 61, 0.18);
}

.diff-name {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 2px;
}

.diff-card[data-diff="easy"] .diff-name { color: #7ff0a8; }
.diff-card[data-diff="normal"] .diff-name { color: var(--accent); }
.diff-card[data-diff="hard"] .diff-name { color: #ff8a5c; }

.diff-desc { font-size: 12.5px; color: var(--text-dim); line-height: 1.5; }

.diff-tag {
  font-size: 11px;
  color: #9fb8a3;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

/* ---------- 7. 按钮 ---------- */
.start-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1.5px;
  padding: 12px 22px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s, filter 0.2s;
  position: relative;
  overflow: hidden;
}

.btn:active { transform: translateY(1px) scale(0.99); }

.btn-primary {
  color: #17240f;
  background: linear-gradient(180deg, #ffe08a, var(--accent) 45%, #e8a91c);
  box-shadow: 0 8px 22px rgba(255, 197, 61, 0.32), inset 0 -3px 0 rgba(140, 90, 0, 0.35);
}

.btn-primary::after {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  animation: sheen 2.8s ease-in-out infinite;
}

@keyframes sheen {
  0% { left: -60%; }
  55%, 100% { left: 130%; }
}

.btn-primary:hover { filter: brightness(1.06); }

.btn-ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(150, 220, 170, 0.3);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- 8. 提示文字 ---------- */
.tips {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed rgba(150, 220, 170, 0.22);
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.85;
}

.tips p { margin: 0 0 4px; }
.tips b { color: #cfe6d3; }

/* ---------- 9. 结算面板 ---------- */
.end-grade {
  margin: 0;
  font-size: clamp(34px, 6vw, 64px);
  line-height: 1;
  letter-spacing: 8px;
  background: linear-gradient(100deg, #fff, var(--accent) 60%, var(--red));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: gradeIn 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes gradeIn {
  from { opacity: 0; transform: scale(0.6) rotate(-6deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.end-comment {
  margin: 6px 0 16px;
  color: var(--text-dim);
  font-size: 13.5px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 9px;
  margin-bottom: 16px;
}

.stat {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(150, 220, 170, 0.16);
  border-radius: 12px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat span { font-size: 11px; color: var(--text-dim); letter-spacing: 1px; }
.stat strong {
  font-size: clamp(16px, 2vw, 21px);
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.detail {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(150, 220, 170, 0.14);
  border-radius: 12px;
  padding: 10px 12px;
  max-height: 148px;
  overflow: auto;
}

.detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 4px 12px;
  font-size: 12.5px;
}

.detail-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  border-bottom: 1px dotted rgba(150, 220, 170, 0.14);
  color: #cfe0d1;
}

.detail-list .d-ok { color: var(--green); font-weight: 700; font-variant-numeric: tabular-nums; }
.detail-list .d-bad { color: #ff8a7a; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- 10. 成绩提交 ---------- */
.submit-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}

.field { flex: 1 1 220px; display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; color: var(--text-dim); letter-spacing: 1px; }

.field input {
  font-family: inherit;
  font-size: 15px;
  padding: 11px 14px;
  border-radius: 11px;
  border: 1px solid rgba(150, 220, 170, 0.3);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 197, 61, 0.18);
}

.submit-hint {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--green);
  min-height: 18px;
}

.submit-hint.is-error { color: #ff9c8f; }

/* ---------- 11. 红榜 ---------- */
.board-tabs {
  display: flex;
  gap: 8px;
  margin: 6px 0 12px;
  flex-wrap: wrap;
}

.tab {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(150, 220, 170, 0.25);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.tab:hover { color: #fff; border-color: rgba(255, 197, 61, 0.5); }

.tab.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1c2408;
  font-weight: 800;
}

.board-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 300px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(150, 220, 170, 0.14);
  background: rgba(0, 0, 0, 0.25);
}

.board-list li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  font-size: 13.5px;
  border-bottom: 1px solid rgba(150, 220, 170, 0.1);
  animation: fadeIn 0.3s ease both;
}

.board-list li:last-child { border-bottom: none; }

.board-list .rk {
  font-weight: 800;
  color: var(--text-dim);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.board-list li:nth-child(1) .rk { color: #ffd75e; }
.board-list li:nth-child(2) .rk { color: #d8e3e8; }
.board-list li:nth-child(3) .rk { color: #e0a06a; }

.board-list .who { display: flex; flex-direction: column; gap: 1px; overflow: hidden; }
.board-list .who b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-list .who small { color: #8ea692; font-size: 11px; }

.board-list .pts {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.board-list li.is-me {
  background: rgba(255, 197, 61, 0.16);
  box-shadow: inset 3px 0 0 var(--accent);
}

.board-status {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
  min-height: 18px;
}

/* ---------- 12. 触屏方向键 ---------- */
.touchpad {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: none;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(2, 46px);
  gap: 8px;
  z-index: 4;
}

.touchpad button {
  border-radius: 12px;
  border: 1px solid rgba(150, 220, 170, 0.35);
  background: rgba(8, 18, 12, 0.72);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
}

.touchpad button:active { background: rgba(255, 197, 61, 0.4); }
.touchpad button[data-dir="up"] { grid-area: 1 / 2; }
.touchpad button[data-dir="left"] { grid-area: 2 / 1; }
.touchpad button[data-dir="down"] { grid-area: 2 / 2; }
.touchpad button[data-dir="right"] { grid-area: 2 / 3; }

/* 触屏设备才显示方向键 */
@media (hover: none) and (pointer: coarse) {
  .touchpad { display: grid; }
}

/* 暂停时隐藏 HUD 交互 */
.is-paused .timebar > i { filter: grayscale(0.7); }

/* ---------- 13. 小屏适配 ---------- */
@media (max-width: 720px) {
  body { padding: 8px; }
  .stage { width: 100vw; border-radius: 14px; }
  .hud { padding: 8px 10px; }
  .pill-label { display: none; }
  .keys-demo { gap: 8px; }
  .key { width: 46px; height: 46px; font-size: 17px; }
  .diff-grid { grid-template-columns: 1fr; }
}

@media (max-height: 620px) {
  .tips { display: none; }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
