:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --text: #e6edf3;
  --muted: #8b949e;
  --red: #e63946;
  --blue: #1d6fb8;
  --yellow: #f4c430;
  --gold: #ffd24a;
  --radius: 16px;
  --max-width: 480px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: radial-gradient(120% 120% at 50% 0%, #1a2330 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC",
    "Microsoft JhengHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Full-screen, no-scroll: pin the body to the real viewport (handles iOS URL bar). */
body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.game {
  width: 100%;
  max-width: var(--max-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
}

/* ---------- Top bar ---------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px;
}
.brand {
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 20px;
}
.brand span { color: var(--gold); }
.balance {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--panel);
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #2a313c;
}
.balance__label { color: var(--muted); font-size: 13px; }
.balance__value { font-weight: 800; font-size: 18px; color: var(--gold); }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  width: 100%;
  flex: 1 1 auto;     /* fill the space left by topbar + controls */
  min-height: 0;      /* allow the flex item to shrink instead of overflowing */
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #2a313c;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.stage__media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Countdown ring */
.countdown {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 64px;
  height: 64px;
  z-index: 5;
  display: grid;
  place-items: center;
}
.countdown__ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.countdown__track { fill: rgba(0,0,0,0.45); stroke: rgba(255,255,255,0.2); stroke-width: 8; }
.countdown__progress {
  fill: none;
  stroke: var(--gold);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}
.countdown__num {
  position: absolute;
  font-weight: 800;
  font-size: 26px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

/* Placeholder "video" reveal animation */
.placeholder {
  display: grid;
  place-items: center;
  background: #05070a;
}
.placeholder__burst {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, var(--reveal, #888) 0%, transparent 60%);
  opacity: 0;
  animation: burst 3.4s ease-in-out forwards;
}
.placeholder__label {
  position: relative;
  z-index: 2;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.7);
}
@keyframes burst {
  0%   { opacity: 0; transform: scale(0.6); }
  35%  { opacity: 0.15; transform: scale(1); }
  70%  { opacity: 0.35; transform: scale(1.05); }
  100% { opacity: 0.9; transform: scale(1.15); }
}

/* Result overlay */
.result {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  /* 較淡的中心暗角 → 結果顯示時影片仍看得見（一直到影片播完） */
  background: radial-gradient(ellipse 80% 55% at 50% 50%,
    rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.28) 60%, rgba(0, 0, 0, 0.12) 100%);
  animation: fadeIn 0.4s ease;
  opacity: 1;
  transition: opacity 0.6s ease;
}
.result.fade-out { opacity: 0; }
.result__color,
.result__amount,
.result__sub { text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85); }
.result__color {
  font-size: 18px;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 999px;
  color: #111;
}
.result__amount {
  font-size: 52px;
  font-weight: 900;
  line-height: 1;
}
.result__amount.win  { color: #4ade80; }
.result__amount.lose { color: #f87171; }
.result__sub { color: var(--muted); font-size: 15px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Controls ---------- */
.controls {
  flex: 0 0 auto;
  background: var(--panel);
  border: 1px solid #2a313c;
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.controls__hint { color: var(--muted); font-size: 13px; text-align: center; }

.amounts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chip {
  padding: 12px 0;
  border-radius: 12px;
  border: 1px solid #2f3742;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.chip:active { transform: scale(0.96); }
.chip--active {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(255,210,74,0.18), rgba(255,210,74,0.05));
  color: var(--gold);
}

.blocks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.block {
  position: relative;
  aspect-ratio: 1 / 0.92;
  max-height: 22vh;
  border-radius: 14px;
  border: 2px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  font-weight: 800;
  transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.block:active { transform: scale(0.97); }
.block--red    { background: linear-gradient(160deg, #ff5a67, var(--red)); }
.block--blue   { background: linear-gradient(160deg, #3a93de, var(--blue)); }
.block--yellow { background: linear-gradient(160deg, #ffe066, var(--yellow)); color: #5a4500; }
.block__name { font-size: 30px; }
.block__bet {
  font-size: 15px;
  background: rgba(0,0,0,0.28);
  padding: 3px 12px;
  border-radius: 999px;
  min-width: 48px;
  text-align: center;
}
.block--yellow .block__bet { background: rgba(0,0,0,0.15); }
.block.has-bet { box-shadow: 0 0 0 3px rgba(255,255,255,0.85), 0 8px 18px rgba(0,0,0,0.4); }
.block.win  { animation: pulseWin 0.8s ease infinite alternate; }
.block.dim  { filter: grayscale(0.7) brightness(0.6); }
@keyframes pulseWin {
  from { box-shadow: 0 0 0 3px rgba(255,255,255,0.9); }
  to   { box-shadow: 0 0 0 8px rgba(255,255,255,0.4); }
}

.controls__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.totalbet { color: var(--muted); font-size: 14px; }
.totalbet span { color: var(--gold); font-weight: 800; }

.btn {
  border: none;
  cursor: pointer;
  font-weight: 700;
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 15px;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn--primary { background: var(--gold); color: #1a1300; }
.btn--ghost { background: transparent; color: var(--muted); border: 1px solid #2f3742; padding: 8px 16px; }

/* Disabled betting state */
.controls.locked .chip,
.controls.locked .block,
.controls.locked .btn--ghost {
  opacity: 0.5;
  pointer-events: none;
}

[hidden] { display: none !important; }
