:root {
  --bg: #fdd32a;
  --gold: #fdd32a;
  --gold-soft: #ffe066;
  --ink: #22345e;
  --panel: rgba(255, 255, 255, 0.94);
  --danger: #e64545;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  font-family: system-ui, 'PingFang TC', 'Noto Sans TC', sans-serif;
  overscroll-behavior: none;
}

/* 舞台:置中的直式遊戲區,填滿視窗但維持可用比例 */
#stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background-color: #fdd32a;
  background-image:
    radial-gradient(circle at 100% 0%, rgba(255, 243, 195, 0.5), transparent 55%),
    radial-gradient(circle at 0% 100%, rgba(255, 243, 195, 0.45), transparent 55%);
}

#webcam,
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 鏡像視訊,符合直覺操作 */
#webcam {
  transform: scaleX(-1);
}

#game {
  z-index: 2;
}

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 0;
  font-size: clamp(20px, 6vw, 30px);
  font-weight: 800;
  pointer-events: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.hud-item {
  background: rgba(18, 27, 66, 0.65);
  padding: 6px 16px;
  border-radius: 999px;
  border: 2px solid rgba(253, 211, 42, 0.6);
}

#timer-box.warning {
  color: var(--danger);
  border-color: var(--danger);
  animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
  to {
    transform: scale(1.12);
  }
}

/* ---- 倒數大字 ---- */
#countdown {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(80px, 30vw, 220px);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 6px 30px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.count-anim {
  animation: pop 0.6s ease-out;
}

@keyframes pop {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  40% {
    transform: scale(1.15);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0.9;
  }
}

/* ---- 全螢幕面板 ---- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2.5vh, 20px);
  padding: clamp(12px, 4vh, 28px) 20px;
  text-align: center;
  background-color: rgba(253, 211, 42, 0.97);
  background-image:
    radial-gradient(circle at 100% 0%, rgba(255, 243, 195, 0.5), transparent 55%),
    radial-gradient(circle at 0% 100%, rgba(255, 243, 195, 0.45), transparent 55%);
  backdrop-filter: blur(6px);
}

.menu-banner {
  width: 100%;
  max-width: 420px;
  height: clamp(90px, 24vh, 220px);
  display: flex;
  justify-content: center;
}

.menu-banner img {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
}

h2 {
  font-size: clamp(28px, 8vw, 44px);
  color: #fff;
}

.text-black {
  color: #1a1a1a;
}

.rules {
  position: relative;
  z-index: 2;
  margin-top: -28px;
  list-style: none;
  text-align: left;
  font-size: clamp(14px, 4.2vw, 17px);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(34, 52, 94, 0.12);
  box-shadow: 0 10px 30px rgba(34, 52, 94, 0.18);
  padding: 4px 20px;
  border-radius: 16px;
  max-width: 420px;
  width: 100%;
}

.rules li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
}

.rule-step:not(.rule-danger) {
  justify-content: center;
  text-align: center;
}

.rule-icon {
  font-size: 1.25em;
  line-height: 1;
  flex-shrink: 0;
  display: inline-flex;
}

.rule-icon img {
  width: 1.5em;
  height: 1.5em;
  object-fit: contain;
}

.rule-text {
  flex: 1;
}

.rule-score .rule-text {
  font-weight: 700;
}

.rule-badge {
  flex-shrink: 0;
  font-weight: 800;
  font-size: 0.85em;
  color: var(--ink);
  background: rgba(253, 211, 42, 0.4);
  padding: 4px 12px;
  border-radius: 999px;
}

.rule-badge.gold {
  color: #fff;
  background: #ff8901;
}

.rules li.rule-divider {
  height: 1px;
  padding: 0;
  margin: 6px 0;
  background: rgba(34, 52, 94, 0.12);
}

.rule-danger .rule-text {
  color: var(--danger);
  font-weight: 700;
}

.rules li.rule-hint {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--ink);
  opacity: 0.65;
  padding-top: 14px;
  margin-top: 4px;
  border-top: 1px solid rgba(34, 52, 94, 0.12);
}

/* ---- 按鈕 ---- */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: clamp(16px, 4.6vw, 20px);
  color: var(--ink);
  background: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.btn:active {
  transform: scale(0.95);
}

a.btn {
  display: inline-block;
  text-decoration: none;
  color: #fff;
  background: var(--ink);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, #ffa733, #ff8901);
  box-shadow: 0 6px 20px rgba(255, 137, 1, 0.45);
}

.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---- 結算 ---- */
.result-card {
  background: var(--panel);
  border: 1px solid rgba(34, 52, 94, 0.12);
  box-shadow: 0 10px 30px rgba(34, 52, 94, 0.18);
  border-radius: 16px;
  padding: 28px 24px 24px;
  max-width: 420px;
  width: 100%;
}

.final-score {
  font-size: clamp(20px, 6vw, 28px);
  color: var(--ink);
  opacity: 0.75;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(34, 52, 94, 0.12);
}

.final-score span {
  font-size: clamp(48px, 16vw, 90px);
  font-weight: 900;
  color: var(--ink);
  display: block;
  margin-top: 4px;
}

#rank-title {
  font-size: clamp(24px, 7vw, 36px);
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 8px;
}

.rank-desc {
  color: var(--ink);
  opacity: 0.75;
}

/* ---- 載入動畫 ---- */
.spinner {
  width: 52px;
  height: 52px;
  border: 5px solid rgba(34, 52, 94, 0.2);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

#loading-text {
  color: var(--ink);
  font-weight: 600;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.hidden {
  display: none !important;
}
