* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 50% 0%, #3a2d6b 0%, #1c1440 55%, #0d0a24 100%);
  color: #fff;
}

#app { position: relative; width: 100vw; height: 100vh; height: 100dvh; }

/*
 * 响应式策略：尺寸/字号一律用 clamp(下限, 首选值(vw/vh/vmin), 上限) 而不是固定 vmin
 * 或固定 px。这样在售货机大触屏（横屏 kiosk，如 1024x600）上元素足够大好点，
 * 在小尺寸预览（手机/平板测试）上又不会撑爆视口。.screen 本身允许纵向滚动兜底：
 * 万一某个极端宽高比下内容仍然放不下，用户还能滚动到，而不是内容被裁掉够不着。
 */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(16px, 5vh, 48px) clamp(16px, 5vw, 48px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; }

/* ---------- 待机页 ---------- */
#screen-idle { gap: clamp(12px, 3vh, 28px); }

.idle-glow {
  position: absolute;
  width: 70vmin; height: 70vmin;
  background: radial-gradient(circle, rgba(255,180,80,0.35) 0%, transparent 70%);
  animation: pulse 3.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.15); opacity: 1; }
}

.idle-title { font-size: clamp(24px, 6vmin, 52px); line-height: 1.3; font-weight: 800; text-shadow: 0 4px 20px rgba(0,0,0,0.5); }
.idle-sub { font-size: clamp(13px, 2.6vmin, 20px); opacity: 0.75; letter-spacing: 0.1em; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(12px, 3vmin, 28px);
  z-index: 1;
}
.game-card {
  width: clamp(120px, 26vmin, 190px);
  height: clamp(120px, 26vmin, 190px);
  border: none;
  border-radius: 24px;
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.12);
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(4px, 1vh, 10px);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.game-card:active { transform: scale(0.94); background: rgba(255,179,71,0.25); }
.game-card-emoji { font-size: clamp(20px, 6vmin, 40px); }
.game-card-name { font-size: clamp(13px, 2.6vmin, 20px); font-weight: 800; }
.game-card-desc { font-size: clamp(10px, 1.8vmin, 15px); opacity: 0.65; }

.btn-huge {
  font-size: clamp(16px, 4vmin, 30px);
  font-weight: 700;
  padding: clamp(14px, 3.2vh, 26px) clamp(28px, 8vw, 64px);
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff9a3d, #ff5f6d);
  color: #fff;
  box-shadow: 0 10px 30px rgba(255, 100, 80, 0.45);
  cursor: pointer;
  animation: bob 2s ease-in-out infinite;
  min-height: 56px;
  min-width: clamp(180px, 40vw, 280px);
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.btn-huge:active { transform: scale(0.95); }

/* ---------- 通用顶栏（游戏页返回菜单）---------- */
.screen-topbar {
  position: absolute; top: clamp(10px, 3vh, 24px); left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; gap: 2vw;
  padding: 0 clamp(12px, 4vw, 32px);
}
.btn-back {
  position: absolute; left: clamp(12px, 4vw, 32px);
  font-size: clamp(12px, 2vmin, 17px); font-weight: 700;
  padding: clamp(6px, 1vh, 12px) clamp(12px, 2vw, 20px);
  border: none; border-radius: 999px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.btn-back:active { background: rgba(255,255,255,0.2); }
.screen-topbar-title { font-size: clamp(14px, 2.4vmin, 20px); font-weight: 700; opacity: 0.75; }

/* ---------- 游戏页通用布局 ----------
 * 四个游戏页（猜拳/井字棋/停轮夹奖/记忆闪光）统一用居中 + gap 布局，
 * 不用 space-between —— space-between 在窄高比屏幕上会把内容硬撑到
 * 撑满整个视口高度，反而把最后一排按钮挤出可视区域。
 */
#screen-rps, #screen-ttt, #screen-wheel, #screen-memory {
  gap: clamp(14px, 2.4vh, 28px);
  padding-top: clamp(56px, 10vh, 96px);
}

.score-row {
  display: flex; align-items: center; gap: 1.5vw;
  font-size: clamp(13px, 2.6vmin, 20px); font-weight: 600; opacity: 0.85;
}
.score-vs { font-size: clamp(11px, 2vmin, 16px); opacity: 0.5; margin: 0 1vw; }
.score-dots { display: inline-flex; gap: 0.8vw; }
.score-dots span {
  width: clamp(8px, 2vmin, 14px); height: clamp(8px, 2vmin, 14px); border-radius: 50%;
  background: rgba(255,255,255,0.2); display: inline-block;
}
.score-dots span.filled { background: #ffb347; box-shadow: 0 0 12px rgba(255,179,71,0.8); }

.arena {
  display: flex; align-items: center; justify-content: center; gap: clamp(24px, 6vw, 80px);
}
.side { display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.5vh, 14px); }
.avatar { font-size: clamp(24px, 9vmin, 56px); }
.move-display {
  font-size: clamp(28px, 14vmin, 80px);
  width: clamp(64px, 22vmin, 140px); height: clamp(64px, 22vmin, 140px);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 3px solid rgba(255,255,255,0.15);
  transition: transform 0.25s ease;
}
.move-display.revealed { animation: reveal 0.4s ease; }
@keyframes reveal { 0% { transform: scale(0.4) rotate(-15deg); opacity: 0; } 100% { transform: scale(1) rotate(0); opacity: 1; } }

#machine-move:not(.revealed) { animation: cycle-pulse 0.18s ease-in-out infinite; }
@keyframes cycle-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(0.9); } }

.vs-badge {
  font-size: clamp(16px, 3.5vmin, 28px); font-weight: 900; opacity: 0.6;
  letter-spacing: 0.05em;
}

.prompt { font-size: clamp(14px, 3.4vmin, 26px); font-weight: 700; min-height: 1.4em; opacity: 0.9; }

.move-buttons { display: flex; gap: clamp(12px, 4vw, 32px); }
.btn-move {
  font-size: clamp(24px, 9vmin, 52px);
  width: clamp(64px, 22vmin, 140px); height: clamp(64px, 22vmin, 140px);
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(2px, 0.5vh, 6px);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn-move span { font-size: clamp(10px, 2.2vmin, 16px); font-weight: 600; opacity: 0.8; }
.btn-move:active { transform: scale(0.9); background: rgba(255,179,71,0.35); }
.btn-move:disabled { opacity: 0.35; }

/* ---------- 单局结果浮层 ---------- */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 20;
}
.overlay.active { opacity: 1; }
.overlay-text {
  font-size: clamp(22px, 8vmin, 56px); font-weight: 900;
  padding: 2vh 6vw; border-radius: 24px;
  background: rgba(255,255,255,0.08);
  transform: scale(0.6);
  transition: transform 0.25s ease;
  text-align: center;
}
.overlay.active .overlay-text { transform: scale(1); }

/* ---------- 赢页 ---------- */
#screen-win { gap: clamp(10px, 2.5vh, 24px); overflow: hidden; }
.win-emoji { font-size: clamp(40px, 16vmin, 110px); animation: bob 1.4s ease-in-out infinite; }
.win-title { font-size: clamp(28px, 8vmin, 56px); font-weight: 900; color: #ffd166; text-shadow: 0 4px 20px rgba(255,209,102,0.5); }
.win-sub { font-size: clamp(13px, 3vmin, 22px); opacity: 0.85; }
.spinner {
  width: clamp(28px, 8vmin, 56px); height: clamp(28px, 8vmin, 56px);
  border: 6px solid rgba(255,255,255,0.2);
  border-top-color: #ffd166;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.win-prize { font-size: clamp(16px, 4vmin, 28px); font-weight: 700; min-height: 1.5em; }

.confetti-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute; top: -5vh;
  width: 1.2vmin; height: 2.4vmin;
  opacity: 0.9;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(115vh) rotate(540deg); opacity: 0.4; }
}

/* ---------- 输页 ---------- */
#screen-lose { gap: clamp(10px, 2.5vh, 24px); }
.lose-emoji { font-size: clamp(36px, 14vmin, 90px); }
.lose-title { font-size: clamp(22px, 6vmin, 42px); font-weight: 800; }
.lose-sub { font-size: clamp(13px, 3vmin, 22px); opacity: 0.8; }
.lose-buttons { display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 1.5vh, 16px); }
.btn-ghost {
  font-size: clamp(12px, 2.4vmin, 18px); font-weight: 600;
  padding: clamp(8px, 1.2vh, 14px) clamp(16px, 4vw, 32px);
  border: none; border-radius: 999px;
  background: transparent;
  color: rgba(255,255,255,0.6);
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- 井字棋 ---------- */
.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 1.6vmin, 16px);
  width: min(66vmin, 86vw, 86vh, 480px);
  height: min(66vmin, 86vw, 86vh, 480px);
}
.ttt-cell {
  border: none;
  border-radius: 16px;
  background: rgba(255,255,255,0.08);
  font-size: clamp(20px, 9vmin, 52px);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.ttt-cell:not(:disabled):active { transform: scale(0.92); background: rgba(255,179,71,0.25); }
.ttt-cell:disabled { cursor: default; }

/* ---------- 停轮夹奖 ---------- */
.wheel-track {
  position: relative;
  width: min(76vw, 640px);
  height: clamp(32px, 6vmin, 52px);
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.15);
}
.wheel-zone {
  position: absolute; top: 0; bottom: 0;
  border-radius: 999px;
  background: rgba(77, 214, 196, 0.45);
  box-shadow: 0 0 20px rgba(77, 214, 196, 0.6) inset;
}
.wheel-marker {
  position: absolute; top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(24px, 5vmin, 40px);
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
}

/* ---------- 记忆闪光 ---------- */
.memory-pad-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(10px, 2vmin, 20px);
  width: min(56vmin, 80vw, 60vh, 400px);
  height: min(56vmin, 80vw, 60vh, 400px);
}
.memory-pad {
  border: none;
  border-radius: 20px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.memory-pad:active { transform: scale(0.94); }
.memory-pad.lit { opacity: 1; box-shadow: 0 0 30px currentColor; }
.pad-0 { background: #ff5f6d; color: #ff5f6d; }
.pad-1 { background: #4dd6c4; color: #4dd6c4; }
.pad-2 { background: #ffd166; color: #ffd166; }
.pad-3 { background: #8e7dff; color: #8e7dff; }
.memory-round { font-size: clamp(12px, 2.2vmin, 18px); opacity: 0.6; font-weight: 600; }

/* ---------- 调试面板（?debug=1 时显示）---------- */
.debug-panel {
  display: none;
  position: fixed; left: 12px; bottom: 12px;
  background: rgba(0,0,0,0.7);
  padding: 10px 14px; border-radius: 10px;
  font-size: 12px; z-index: 999;
  max-width: calc(100vw - 24px);
}
.debug-panel.visible { display: block; }
.debug-panel label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- 横屏矮屏（多数售货机触屏，如 1024x600）进一步收紧 ---------- */
@media (max-height: 480px) {
  #screen-rps, #screen-ttt, #screen-wheel, #screen-memory { padding-top: clamp(44px, 14vh, 72px); }
}
