/* Late-loaded game layout fixes. Keep this file after final.css. */
:root {
  --game-stage-height: 620px;
  --game-stage-radius: 24px;
}

.game-layout.game-ui-enhanced {
  height: var(--game-stage-height);
  min-height: var(--game-stage-height);
  max-height: var(--game-stage-height);
  overflow: hidden;
  isolation: isolate;
}

.game-ui-enhanced .game-stage {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  contain: layout paint;
}

.game-ui-enhanced .game-controls {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

.game-ui-enhanced .game-stage > * {
  max-width: 100%;
  min-width: 0;
}

/* Results are already sent to #toasts by gameResult(). */
.game-ui-enhanced #resultBanner,
.game-ui-enhanced #resultBanner .game-result {
  display: none !important;
}

.toast-stack {
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
}

.game-guide {
  width: min(860px, 100%);
  margin: 14px auto 0;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, .025);
  color: var(--muted);
  overflow: hidden;
}

.game-guide summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 17px;
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  list-style: none;
  user-select: none;
}

.game-guide summary::-webkit-details-marker { display: none; }
.game-guide summary::after { content: "+"; color: var(--green); font-size: 20px; }
.game-guide[open] summary::after { content: "-"; }
.game-guide-body { padding: 0 17px 16px; font-size: 12px; line-height: 1.65; }
.game-ui-enhanced .game-help { display: none !important; }

/* Stable controls: selecting an option never changes the grid geometry. */
.game-ui-enhanced .choice-grid { grid-auto-rows: 43px; align-items: stretch; }
.game-ui-enhanced .choice-btn {
  width: 100%;
  min-width: 0;
  min-height: 43px;
  padding: 8px;
  box-sizing: border-box;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  transform: none !important;
}
.game-ui-enhanced .choice-btn.active { border-width: 1px; }

/* Dice occupies the same box before, during and after its roll. */
.game-ui-dice .game-stage > div {
  width: 260px;
  height: 280px;
  display: grid;
  grid-template-rows: 40px 200px;
  place-items: center;
}

.game-ui-dice .game-stage .muted { margin: 0 !important; align-self: start; }
.game-ui-dice .die {
  width: 180px;
  height: 180px;
  min-width: 180px;
  min-height: 180px;
  box-sizing: border-box;
  line-height: 1;
  transform-origin: 50% 50%;
  will-change: transform;
}

/* The coin always remains a true circle, including narrow layouts. */
.game-ui-coin .coin {
  flex: 0 0 clamp(158px, 30vw, 190px);
  width: clamp(158px, 30vw, 190px);
  height: clamp(158px, 30vw, 190px);
  min-width: 158px;
  min-height: 158px;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  transform-origin: center;
  will-change: transform;
}

.game-ui-coin .coin-face { width: 100%; height: 100%; box-sizing: border-box; }

/* Mines board and metrics keep their footprint after reveal/cashout. */
.game-ui-mines .game-stage > div { width: min(500px, 100%) !important; }
.game-ui-mines .mine-toolbar { min-height: 62px; }
.game-ui-mines .mines { width: min(440px, 100%); margin-inline: auto; }
.game-ui-mines .mine-cell { min-width: 0; min-height: 0; box-sizing: border-box; }

/* Blackjack hands do not resize the entire arena as cards are added. */
.game-ui-blackjack .cards-table { height: 500px; grid-template-rows: 1fr 1fr; align-content: center; }
.game-ui-blackjack .hand { min-height: 155px; max-width: 100%; overflow: visible; }

/* Crash gets a fixed arena, readable grid, rocket and flame. */
.game-ui-crash .crash-wrap { width: min(720px, 100%); }
.game-ui-crash .crash-value {
  min-height: 105px;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}

.game-ui-crash .crash-track {
  height: 300px;
  margin-top: 14px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 18px;
  background-color: rgba(3, 12, 8, .42);
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px),
    radial-gradient(circle at 78% 18%, rgba(143, 240, 173, .13), transparent 36%);
  background-size: 44px 44px, 44px 44px, auto;
}

.crash-hud {
  position: absolute;
  z-index: 2;
  inset: 14px 14px auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.crash-live { display: inline-flex; align-items: center; gap: 7px; color: var(--green); }
.crash-live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 13px currentColor;
}

.game-ui-crash .rocket {
  width: 45px;
  height: 58px;
  display: block;
  font-size: 0 !important;
  overflow: visible;
  transform: rotate(48deg);
  transform-origin: 50% 70%;
  filter: drop-shadow(-10px 14px 12px rgba(244, 200, 98, .25));
}

.game-ui-crash .rocket::before {
  content: "";
  position: absolute;
  inset: 0 8px 13px;
  border-radius: 70% 70% 38% 38%;
  background: linear-gradient(135deg, #f8fff9 0 35%, var(--green) 36% 70%, var(--green-2) 71%);
  clip-path: polygon(50% 0, 100% 70%, 80% 100%, 20% 100%, 0 70%);
}

.game-ui-crash .rocket::after {
  content: "";
  position: absolute;
  left: 16px;
  bottom: -11px;
  width: 13px;
  height: 29px;
  border-radius: 50% 50% 80% 80%;
  background: linear-gradient(#fff6b2, #ffb347 45%, rgba(255, 91, 41, 0));
  filter: blur(.4px) drop-shadow(0 6px 8px #ff8245);
  animation: gameFlame .13s ease-in-out infinite alternate;
}

@keyframes gameFlame { to { height: 23px; transform: translateY(3px) scaleX(.78); } }

/* Centering math is based on the viewport, never on the long strip. */
.game-ui-jackpot .game-stage { padding-inline: clamp(16px, 4vw, 36px); }
.game-ui-jackpot .game-stage > div { width: min(760px, 100%) !important; overflow: hidden; }
.game-ui-jackpot .jackpot-line {
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  box-sizing: border-box;
  contain: layout paint;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}

.game-ui-jackpot .jackpot-strip {
  width: max-content;
  min-width: 100%;
  max-width: none;
  box-sizing: border-box;
  transform-origin: left center;
  transition-duration: 5s !important;
  will-change: transform;
}

.game-ui-jackpot .jackpot-entry {
  flex: 0 0 120px;
  width: 120px;
  min-width: 120px;
  box-sizing: border-box;
}

.game-ui-jackpot .jackpot-wheel { transition-duration: 5s !important; }
.game-ui-jackpot #jackpotStatus { min-height: 18px; font-variant-numeric: tabular-nums; }
.game-ui-jackpot .players-list { min-height: 52px; max-height: 154px; scrollbar-gutter: stable; }

@media (max-width: 980px) {
  :root { --game-stage-height: auto; }
  .game-layout.game-ui-enhanced {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }
  .game-ui-enhanced .game-stage { height: 470px; min-height: 470px; }
  .game-ui-enhanced .game-controls { max-height: none; overflow: visible; }
  .game-ui-blackjack .cards-table { height: 430px; }
}

@media (max-width: 560px) {
  .game-ui-enhanced .game-stage { height: 390px; min-height: 390px; padding: 14px; }
  .game-ui-mines .game-stage { height: 430px; min-height: 430px; }
  .game-ui-blackjack .game-stage { height: 450px; min-height: 450px; }
  .game-ui-jackpot .game-stage { height: 330px; min-height: 330px; }
  .game-ui-crash .crash-value { min-height: 72px; font-size: clamp(50px, 16vw, 76px); }
  .game-ui-crash .crash-track { height: 235px; }
  .game-ui-dice .game-stage > div { transform: scale(.88); }
  .game-ui-jackpot .jackpot-line { height: 132px; }
  /* Keep the 120px card + 10px gap used by the server-wheel centering math. */
  .game-ui-jackpot .jackpot-entry { height: 94px; }
}

@media (prefers-reduced-motion: reduce) {
  .game-ui-crash .rocket::after { animation: none; }
  .game-ui-jackpot .jackpot-strip,
  .game-ui-jackpot .jackpot-wheel { transition-duration: .01ms !important; }
}
