/*
 * WildGame shared HUD — one control bar for every studio slot.
 *
 * Anatomy (same in every game): utility buttons · balance · bet · win ·
 * optional buy-bonus · spin cluster (bet −/+, autoplay, turbo around a round
 * spin button). Desktop is a single full-width bar; portrait phones stack it
 * into three rows. A game only sets the --wg-* theme tokens below; it never
 * restyles the components. Buttons stay flat and tactile; the bar's surface
 * material is supplied by the game's theme tokens.
 */
.wg-hud {
  /* Theme tokens — override per game (and per mode) */
  --wg-bg: rgba(6, 10, 16, .9);
  --wg-bg-solid: var(--wg-bg);
  --wg-surface: none;
  --wg-backdrop: none;
  --wg-control-backdrop: none;
  --wg-surface-shadow: none;
  --wg-line: rgba(255, 255, 255, .1);
  --wg-accent: #ffcf4a;          /* labels, active toggles, buy bonus */
  --wg-accent-ink: #1b1206;      /* text on accent */
  --wg-accent-dark: #8a6510;     /* buy bonus pressed edge */
  --wg-value: #fff;
  --wg-spin: #c8303f;
  --wg-spin-dark: #6e1622;
  --wg-ring: rgba(255, 255, 255, .92);
  --wg-chip: rgba(255, 255, 255, .08);
  --wg-chip-line: rgba(255, 255, 255, .3);
  --wg-font: 'Helvetica Neue', Arial, sans-serif;

  /* Geometry — desktop */
  --wg-h: 104px;
  --wg-btn: 48px;
  --wg-btn-sm: 42px;
  --wg-spin-size: 96px;
  --wg-spin-raise: 30px;

  position: relative;
  z-index: 5;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 28px;
  width: 100%;
  height: var(--wg-h);
  padding: 0 max(28px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(28px, env(safe-area-inset-left));
  background: var(--wg-bg);
  background-image: var(--wg-surface);
  -webkit-backdrop-filter: var(--wg-backdrop);
  backdrop-filter: var(--wg-backdrop);
  box-shadow: var(--wg-surface-shadow);
  border-top: 1px solid var(--wg-line);
  border-image-source: var(--wg-edge, none);
  border-image-slice: 1;
  font-family: var(--wg-font);
  color: var(--wg-value);
  user-select: none;
  -webkit-user-select: none;
}
.wg-hud *, .wg-hud *::before, .wg-hud *::after { box-sizing: border-box; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .wg-hud { background-color: var(--wg-bg-solid); }
}
@media (prefers-reduced-transparency: reduce) {
  .wg-hud { background: var(--wg-bg-solid); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
.wg-hud button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.wg-hud button:disabled { cursor: default; }
.wg-hud [hidden] { display: none !important; }

/* Stats */
.wg-hud .wg-stat { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.wg-hud .wg-label { font-size: 11px; line-height: 1; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; color: var(--wg-accent); }
.wg-hud .wg-value { font-size: 22px; line-height: 1.15; font-weight: 800; color: var(--wg-value); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wg-hud .wg-win { flex: 1; align-items: center; text-align: center; }
.wg-hud .wg-win .wg-value { font-size: 28px; }
.wg-hud .wg-bet-value { display: inline-flex; align-items: center; gap: 8px; padding: 0; min-height: 30px; border: 0; background: none; text-align: left; }
.wg-hud .wg-bet-value:not(:disabled):hover .wg-value { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; text-decoration-color: var(--wg-accent); }
.wg-hud .wg-lock { display: none; width: 14px; height: 14px; filter: brightness(0) invert(1); opacity: .7; }

/* Round utility / small buttons */
.wg-hud .wg-utility { display: flex; gap: 10px; }
.wg-hud .wg-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--wg-btn); height: var(--wg-btn); padding: 0;
  border: 1.5px solid var(--wg-chip-line); border-radius: 50%;
  background: var(--wg-chip);
  -webkit-backdrop-filter: var(--wg-control-backdrop);
  backdrop-filter: var(--wg-control-backdrop);
  transition: transform .08s ease, background-color .12s ease, border-color .12s ease;
}
.wg-hud .wg-btn img { width: 42%; height: 42%; filter: brightness(0) invert(1); pointer-events: none; }
.wg-hud .wg-btn.wg-sm { width: var(--wg-btn-sm); height: var(--wg-btn-sm); }
.wg-hud .wg-btn[aria-pressed='true'] { border-color: var(--wg-accent); background: color-mix(in srgb, var(--wg-accent) 16%, transparent); }
.wg-hud #turboBtn[aria-pressed='true'] img,
.wg-hud #autoBtn[aria-pressed='true'] img { filter: none; opacity: 1; }
.wg-hud .wg-btn:disabled { opacity: .35; }
@media (prefers-reduced-transparency: reduce) {
  .wg-hud .wg-btn { -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* Spin cluster: the spin button sits raised above the bar */
.wg-hud .wg-spin-cluster { display: flex; align-items: center; gap: 12px; flex: none; margin-top: calc(-1 * var(--wg-spin-raise)); }
.wg-hud .wg-side { display: flex; flex-direction: column; gap: 8px; margin-top: var(--wg-spin-raise); }
.wg-hud .wg-spin {
  position: relative; display: grid; place-items: center; flex: none;
  width: var(--wg-spin-size); height: var(--wg-spin-size); padding: 0;
  border: 4px solid var(--wg-ring); border-radius: 50%;
  background: var(--wg-spin);
  box-shadow: 0 5px 0 var(--wg-spin-dark), 0 10px 18px rgba(0, 0, 0, .45);
  transition: transform .08s ease, box-shadow .08s ease;
}
.wg-hud .wg-spin .spin-icon { width: 48%; height: 48%; filter: brightness(0) invert(1); pointer-events: none; }
.wg-hud .wg-spin:disabled { opacity: .7; }
.wg-hud .wg-auto-count { display: none; font-size: calc(var(--wg-spin-size) * .3); font-weight: 900; font-variant-numeric: tabular-nums; color: #fff; }
.wg-hud .wg-spin.is-auto .spin-icon { display: none; }
.wg-hud .wg-spin.is-auto .wg-auto-count { display: block; }
.wg-hud .wg-bonus-counter { cursor: default; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.wg-hud .wg-bonus-counter strong { font-size: calc(var(--wg-spin-size) * .34); font-variant-numeric: tabular-nums; }
.wg-hud .wg-bonus-counter span { margin-top: 3px; font-size: 10px; font-weight: 700; letter-spacing: 1.4px; }

/* Buy bonus (only in games that have it) */
.wg-hud .wg-buy {
  display: flex; flex-direction: column; align-items: center; justify-content: center; flex: none;
  min-width: 150px; min-height: 58px; padding: 8px 16px;
  border: 0; border-radius: 10px;
  background: var(--wg-accent); color: var(--wg-accent-ink);
  box-shadow: 0 4px 0 var(--wg-accent-dark);
  text-align: center; transition: transform .08s ease, box-shadow .08s ease;
}
.wg-hud .wg-buy span { font-size: 12px; font-weight: 800; letter-spacing: 1.4px; }
.wg-hud .wg-buy strong { font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; }
.wg-hud .wg-buy:disabled { opacity: .45; }
.wg-hud .wg-bonus-progress { background: transparent; color: var(--wg-accent); box-shadow: inset 0 0 0 1.5px var(--wg-accent); }
.wg-hud .wg-bonus-progress strong { font-size: 13px; letter-spacing: 1.2px; color: var(--wg-value); }

/* Pressed states: one clear scale-down */
.wg-hud .wg-btn:not(:disabled):active { transform: scale(.94); }
.wg-hud .wg-spin:not(:disabled):active { transform: translateY(3px) scale(.95); box-shadow: 0 2px 0 var(--wg-spin-dark), 0 5px 10px rgba(0, 0, 0, .45); }
.wg-hud .wg-buy:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 var(--wg-accent-dark); }
@media (hover: hover) {
  .wg-hud .wg-btn:not(:disabled):hover { border-color: rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .14); }
  .wg-hud .wg-spin:not(:disabled):hover { filter: brightness(1.08); }
  .wg-hud .wg-buy:not(:disabled):hover { filter: brightness(1.06); }
}
.wg-hud button:focus-visible { outline: 3px solid var(--wg-accent); outline-offset: 3px; }

/* Bonus round: bet is locked */
.wg-hud.in-bonus .wg-lock { display: block; }
.wg-hud.in-bonus #betMinus, .wg-hud.in-bonus #betPlus, .wg-hud.in-bonus #autoBtn { visibility: hidden; }

/* Spinning indicator on the spin icon */
.wg-hud.is-spinning .wg-spin:not(.is-auto) .spin-icon { animation: wg-spin-turn .9s linear infinite; }
@keyframes wg-spin-turn { to { transform: rotate(360deg); } }

/* ---------- Portrait phones: three rows ----------
   balance · bet · win
   menu · − · SPIN · + · autoplay
   turbo · buy bonus · sound            */
@media (max-aspect-ratio: 4/5), (max-width: 864px) and (min-height: 541px) {
  .wg-hud {
    --wg-h: auto; --wg-btn: 48px; --wg-btn-sm: 48px; --wg-spin-size: 90px; --wg-spin-raise: 0px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-areas: 'bal bal bet win win' 'menu minus spin plus auto' 'turbo buy buy buy sound';
    align-items: center; justify-items: center;
    gap: 10px 4px;
    padding: 12px max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .wg-hud .wg-utility, .wg-hud .wg-spin-cluster, .wg-hud .wg-side { display: contents; }
  .wg-hud #rulesBtn { display: none; }
  .wg-hud #menuBtn { grid-area: menu; }
  .wg-hud #soundBtn { grid-area: sound; }
  .wg-hud #betMinus { grid-area: minus; }
  .wg-hud #betPlus { grid-area: plus; }
  .wg-hud #autoBtn { grid-area: auto; }
  .wg-hud #turboBtn { grid-area: turbo; }
  .wg-hud .wg-spin { grid-area: spin; }
  .wg-hud .wg-buy { grid-area: buy; width: 100%; min-width: 0; min-height: 52px; padding: 6px 10px; }
  .wg-hud .wg-balance { grid-area: bal; justify-self: start; align-items: flex-start; }
  .wg-hud .wg-bet { grid-area: bet; align-items: center; }
  .wg-hud .wg-win { grid-area: win; justify-self: end; align-items: flex-end; text-align: right; }
  .wg-hud .wg-value, .wg-hud .wg-win .wg-value { font-size: 19px; }
  .wg-hud .wg-label { font-size: 10px; letter-spacing: 1.3px; }
}

/* ---------- Landscape phones: one compact row ---------- */
@media (max-height: 540px) and (min-aspect-ratio: 4/5) {
  .wg-hud { --wg-h: 70px; --wg-btn: 40px; --wg-btn-sm: 36px; --wg-spin-size: 64px; --wg-spin-raise: 12px; gap: 14px; padding-inline: max(14px, env(safe-area-inset-left)); }
  .wg-hud .wg-value, .wg-hud .wg-win .wg-value { font-size: 17px; }
  .wg-hud .wg-label { font-size: 9px; letter-spacing: 1.1px; }
  .wg-hud .wg-utility { gap: 6px; }
  .wg-hud .wg-side { gap: 4px; flex-direction: row; margin-top: var(--wg-spin-raise); }
  .wg-hud .wg-buy { min-width: 112px; min-height: 46px; padding: 4px 10px; }
  .wg-hud .wg-buy span { font-size: 10px; }
  .wg-hud .wg-buy strong { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .wg-hud.is-spinning .wg-spin .spin-icon { animation: none; }
  .wg-hud .wg-btn, .wg-hud .wg-spin, .wg-hud .wg-buy { transition: none; }
}
