/* ============================================================
 * 牧遥游戏 · 俄罗斯方块 — 霓虹高保真主题
 * 深色网格纹理 + 霓虹光晕 + 伪3D方块 + 响应式
 * ============================================================ */
:root {
  --bg-1: #070b17;
  --bg-2: #0d1226;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-border: rgba(120, 160, 255, 0.16);
  --text: #e9efff;
  --text-dim: #7e8bb0;
  --neon: #00e5ff;
  --neon-2: #c77dff;
  --gold: #ffd166;
  --danger: #ff4d6d;
  --radius: 14px;
  --shadow: 0 14px 44px rgba(0, 0, 0, 0.5);
}

/* ============ 基础 ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui,
    -apple-system, sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* 霓虹氛围光斑（纯 CSS 动画背景） */
body::before,
body::after {
  content: "";
  position: fixed;
  width: 60vmax;
  height: 60vmax;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.16;
  z-index: -1;
  animation: blob-drift 18s ease-in-out infinite alternate;
}

body::before {
  top: -20vmax;
  left: -15vmax;
  background: radial-gradient(circle, var(--neon), transparent 65%);
}

body::after {
  bottom: -22vmax;
  right: -15vmax;
  background: radial-gradient(circle, var(--neon-2), transparent 65%);
  animation-delay: -9s;
}

@keyframes blob-drift {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(6vmax, 4vmax) scale(1.15);
  }
}

.game-wrap {
  width: 100%;
  max-width: 880px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* ============ 标题 ============ */
.game-header {
  text-align: center;
}

.game-header h1 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  letter-spacing: 0.18em;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 0 18px rgba(0, 229, 255, 0.45);
}

.game-header .logo {
  margin-left: 0.35em;
  font-size: 0.62em;
  letter-spacing: 0.3em;
  background: linear-gradient(90deg, var(--neon), var(--neon-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 22px rgba(199, 125, 255, 0.5);
}

.game-header .subtitle {
  margin-top: 5px;
  color: var(--text-dim);
  font-size: 0.78rem;
  letter-spacing: 0.32em;
}

/* 音频状态调试条 */
.audio-status {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

/* ============ 主布局 ============ */
.game-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(12px, 2.5vw, 26px);
}

/* ============ 面板 ============ */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  width: 190px;
}

.panel h3 {
  font-size: 0.76rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
  font-weight: 600;
}

/* 操作说明 */
.controls {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.controls li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.keys {
  display: inline-flex;
  gap: 4px;
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 6px;
  text-align: center;
  font-family: inherit;
  font-size: 0.7rem;
  color: var(--text);
  background: rgba(0, 229, 255, 0.08);
  border: 1px solid rgba(0, 229, 255, 0.22);
  border-bottom-width: 2px;
  border-radius: 6px;
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.12);
}

/* ============ 右侧面板 ============ */
.panel-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-box {
  text-align: center;
}

.preview-box h3 {
  margin-bottom: 6px;
}

#hold,
#next {
  width: 104px;
  height: 104px;
  margin: 0 auto;
  display: block;
}

#hold {
  border: 1px dashed rgba(120, 160, 255, 0.25);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

.stat-label {
  font-size: 0.76rem;
  color: var(--text-dim);
  letter-spacing: 0.14em;
}

.stat-value {
  font-size: 1.22rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-shadow: 0 0 12px rgba(0, 229, 255, 0.35);
  transition: transform 0.15s ease, color 0.15s ease;
}

.stat-value.pop {
  transform: scale(1.4);
  color: var(--neon);
}

/* 速度调节 */
.speed-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

.speed-row input[type="range"] {
  flex: 1;
  min-width: 60px;
  accent-color: var(--neon);
  cursor: pointer;
  height: 22px;
}

.speed-btn {
  padding: 5px 9px;
  font-size: 0.95rem;
  line-height: 1;
  min-width: 28px;
  flex-shrink: 0;
  border-radius: 8px;
}

.speed-value {
  font-size: 0.95rem;
  min-width: 2.4em;
  text-align: right;
  color: var(--neon);
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn {
  flex: 1;
}

/* ============ 按钮 ============ */
.btn {
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  touch-action: manipulation;
}

.btn:hover {
  background: rgba(0, 229, 255, 0.14);
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.22);
  transform: translateY(-1px);
}

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

.btn:focus-visible {
  outline: 2px solid var(--neon);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--neon), var(--neon-2));
  border: none;
  color: #060a16;
  box-shadow: 0 6px 24px rgba(0, 229, 255, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #33ecff, #d9a6ff);
  box-shadow: 0 8px 30px rgba(0, 229, 255, 0.5);
}

/* ============ 游戏主区 ============ */
.board-area {
  position: relative;
  flex-shrink: 0;
  width: min(38vh, 300px, 78vw);
}

#board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 2;
  background: #0a0f22;
  border: 1px solid rgba(0, 229, 255, 0.28);
  border-radius: 12px;
  box-shadow: 0 0 28px rgba(0, 229, 255, 0.16),
    inset 0 0 70px rgba(0, 0, 0, 0.55), var(--shadow);
  animation: board-glow 3.2s ease-in-out infinite alternate;
}

@keyframes board-glow {
  from {
    box-shadow: 0 0 20px rgba(0, 229, 255, 0.12),
      inset 0 0 70px rgba(0, 0, 0, 0.55), var(--shadow);
  }
  to {
    box-shadow: 0 0 36px rgba(199, 125, 255, 0.28),
      inset 0 0 70px rgba(0, 0, 0, 0.55), var(--shadow);
  }
}

/* ============ 覆盖层 ============ */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 8, 18, 0.74);
  backdrop-filter: blur(7px);
  border-radius: 12px;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-box {
  text-align: center;
  padding: 28px 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: overlay-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes overlay-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.overlay-box h2 {
  font-size: clamp(1.3rem, 4vw, 1.9rem);
  letter-spacing: 0.22em;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 0 20px rgba(0, 229, 255, 0.5);
}

.overlay-box p {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.9;
}

.overlay-box .final-score {
  color: var(--neon);
  font-size: 1.2rem;
  font-weight: 800;
  text-shadow: 0 0 14px rgba(0, 229, 255, 0.6);
}

/* ============ 提示气泡 ============ */
.toast {
  position: absolute;
  left: 50%;
  top: 36%;
  transform: translate(-50%, -50%) scale(0.8);
  padding: 10px 24px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.14em;
  color: #060a16;
  background: linear-gradient(135deg, var(--neon), var(--neon-2));
  box-shadow: 0 8px 34px rgba(0, 229, 255, 0.45);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.25s ease,
    transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.toast.score {
  background: linear-gradient(135deg, #ffd166, #ff9e40);
  box-shadow: 0 8px 34px rgba(255, 158, 64, 0.45);
}

/* ============ 夸赞弹窗字幕 ============ */
.praise {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(0.3);
  font-size: clamp(1.2rem, 5vh, 2rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: #fff;
  text-shadow:
    0 0 14px rgba(255, 209, 102, 0.95),
    0 0 34px rgba(255, 94, 122, 0.6),
    0 2px 8px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  z-index: 15;
}

.praise.show {
  animation: praise-pop 1.15s cubic-bezier(0.2, 0.9, 0.3, 1.3) forwards;
}

@keyframes praise-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2) rotate(-6deg);
  }
  18% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.3) rotate(3deg);
  }
  32% {
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
  78% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.06) translateY(-6px);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.25) translateY(-22px);
  }
}

/* ============ 触屏控制 ============ */
/* 默认显示（保证手机/平板一定能看到按钮）；
   仅当「大屏 + 鼠标指针」时才隐藏（此时用键盘操作） */
.touch-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 460px;
}

.touch-btn {
  flex: 1;
  min-width: 52px;
  padding: 14px 10px;
  font-size: 1.1rem;
}

/* ============ 响应式 ============ */
@media (max-width: 780px) {
  body {
    padding-bottom: 96px; /* 给固定底部控制条留空间，避免遮挡 */
  }

  .panel-left {
    display: none;
  }

  .game-layout {
    flex-wrap: wrap;
    gap: 12px;
  }

  /* 棋盘按屏幕高度适配，保证一屏内不滚动 */
  .board-area {
    width: min(30vh, 280px, 92vw);
  }

  .panel-right {
    width: min(30vh, 280px, 92vw);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
  }

  .preview-box {
    width: auto;
  }

  .preview-box h3 {
    margin-bottom: 4px;
    font-size: 0.66rem;
  }

  #hold,
  #next {
    width: 56px;
    height: 56px;
  }

  .stat {
    flex: 1;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 4px;
  }

  .stat-value {
    font-size: 1rem;
  }

  .speed-row {
    width: 100%;
    padding: 6px 8px;
  }

  .btn-row {
    width: 100%;
  }

  /* 底部固定控制条：拇指区域常驻，无需滚动 */
  .touch-controls {
    position: fixed;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    max-width: 100%;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgba(7, 11, 23, 0.93);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--panel-border);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
    z-index: 30;
  }

  .touch-btn {
    min-width: 0;
    padding: 12px 6px;
    font-size: 1.05rem;
  }
}

@media (min-width: 901px) and (pointer: fine) {
  .touch-controls {
    display: none;
  }
}

/* 降低动画偏好 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  body::before,
  body::after {
    animation: none;
  }
}
