/* X24 Originals — Shared mobile UI normalization
 * Uniformazione touch-target, font, spacing su Crash/Mines/Dice/Limbo/Plinko/Wheel/HiLo.
 * Si applica solo a mobile portrait/tablet (≤ 768px). Desktop intoccato.
 * Override aggressivo (!important) perché i 7 HTML hanno CSS inline molto specifico.
 */

@media (max-width: 768px) {
  /* ── Touch target minimi (iOS HIG: 44px) ─────────────────────────────── */
  body button,
  body input[type="button"],
  body input[type="submit"],
  body label[role="button"],
  body [class*="-btn"],
  body [class*="btn-"],
  body [class*="-tab"],
  body [class*="tab-"],
  body [class*="chip"],
  body [class*="preset"],
  body [class*="quick"] {
    min-height: 44px !important;
    font-size: 14px !important;
    letter-spacing: 0.5px !important;
  }

  /* Bottoni primari (BET, LAUNCH, SPIN, DROP BALL, REVEAL, CASHOUT) */
  body button#bet-btn,
  body button#launch-btn,
  body button#spin-btn,
  body button#drop-btn,
  body button#cashout-btn,
  body button#play-btn,
  body button[class*="primary"],
  body button[id*="primary"],
  body button[class*="cta"],
  body .ms-primary,
  body .btn-primary,
  body .primary-btn {
    min-height: 56px !important;
    font-size: 17px !important;
    font-weight: 800 !important;
    letter-spacing: 1.5px !important;
    border-radius: 12px !important;
    padding: 14px 18px !important;
  }

  /* Bottoni Under/Over Dice + Higher/Lower HiLo: 2 colonne ben dimensionate */
  body button[id*="under"],
  body button[id*="over"],
  body button[id*="higher"],
  body button[id*="lower"],
  body .bet-under,
  body .bet-over {
    min-height: 64px !important;
    font-size: 16px !important;
    font-weight: 800 !important;
  }

  /* ── Bet amount input più visibile ──────────────────────────────────── */
  body input[type="number"],
  body input[type="text"][id*="bet"],
  body input[id*="amount"],
  body input[id*="stake"] {
    font-size: 18px !important;
    font-weight: 700 !important;
    min-height: 48px !important;
    padding: 12px 14px !important;
  }

  /* ── Etichette (RISK, MINES, ROWS, ecc.) leggibili ─────────────────── */
  body label,
  body [class*="label"]:not(button) {
    font-size: 11px !important;
    letter-spacing: 1.2px !important;
    text-transform: uppercase !important;
  }

  /* ── Multiplier display grande e centrale (Limbo, Crash, Mines preview) */
  body [class*="multiplier"],
  body [id*="multiplier"],
  body [class*="payout"],
  body [id*="payout"] {
    font-size: 22px !important;
    font-weight: 800 !important;
  }

  /* Display centrale "1.00x" (Limbo) / "6.59x" (Crash) lasciato grande
     ma con safe-area perché alcuni font erano troppo grossi per portrait */
  body .big-multiplier,
  body #big-multiplier,
  body [class*="big-mul"] {
    font-size: clamp(48px, 14vw, 96px) !important;
    line-height: 1.05 !important;
  }

  /* ── Tab MANUAL / AUTO uniformi ──────────────────────────────────── */
  body [class*="tab"],
  body [role="tab"] {
    padding: 12px 16px !important;
    font-weight: 800 !important;
    letter-spacing: 1.5px !important;
  }

  /* ── Pannelli bet — padding interno più generoso ─────────────────── */
  body [class*="bet-panel"],
  body [id*="bet-panel"],
  body [class*="game-panel"],
  body [id*="game-panel"],
  body .panel,
  body #panel {
    padding: 14px 12px !important;
    border-radius: 14px !important;
  }

  /* ── Quick bet chips uniformi (€1, €5, €10, €25, €50) ──────────────── */
  body [class*="chip-row"],
  body [class*="quick-row"],
  body [id*="quick-row"] {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    gap: 6px !important;
  }
  body [class*="chip-row"] button,
  body [class*="quick-row"] button {
    min-height: 40px !important;
    font-size: 13px !important;
    padding: 0 4px !important;
  }

  /* ── Risk/Rows pill buttons (LOW/MEDIUM/HIGH, 8/12/16) ───────────── */
  body [class*="risk-row"] button,
  body [class*="rows-row"] button,
  body [id*="risk"] button,
  body [id*="rows"] button {
    min-height: 44px !important;
    font-size: 12px !important;
    font-weight: 800 !important;
    letter-spacing: 1.5px !important;
  }

  /* ── Plus/Minus stepper (Mines count, ecc.) ──────────────────────── */
  body button[class*="plus"],
  body button[class*="minus"],
  body button[id*="plus"],
  body button[id*="minus"] {
    min-width: 48px !important;
    min-height: 48px !important;
    font-size: 20px !important;
  }

  /* ── Body text base: 14px minimo per readability ─────────────────── */
  body { font-size: 14px !important; }

  /* ── Header height + padding consistente ─────────────────────────── */
  body { padding-top: 48px !important; }
  body #game-header {
    height: 48px !important;
    padding: 0 12px !important;
    gap: 8px !important;
  }
  body #game-header button,
  body #game-header a {
    font-size: 12px !important;
    padding: 8px 12px !important;
    min-height: 40px !important;
  }
  body #game-header [id*="balance"],
  body #game-header [class*="balance"] {
    font-size: 13px !important;
    font-weight: 800 !important;
  }

  /* ── Crash mobile-sheet: 25vh ULTRA-COMPATTO (Stake-grade).
        Budget altezza sheet ~213px (iPhone Pro 852×0.25):
          tabs(28+2) + bet-row(32+2) + chips(28+2) + cashout-row(32) + cta(46) + padding(6)
          ≈ 178px → margine ~35px. */
  body.mobile-mode #mobile-sheet {
    height: calc(200px + env(safe-area-inset-bottom, 0px)) !important;
    max-height: calc(200px + env(safe-area-inset-bottom, 0px)) !important;
    padding: 2px 12px max(8px, env(safe-area-inset-bottom, 8px)) !important;
    overflow: hidden !important; /* niente scroll bounce iOS */
    overscroll-behavior: contain !important;
    touch-action: none !important; /* previene "drag" sheet su touch */
    display: flex !important;
    flex-direction: column !important;
    bottom: 0 !important;
  }
  /* Permetti tap/click ai bottoni dentro il sheet (touch-action:none disabilita
     anche i tap se non override). */
  body.mobile-mode #mobile-sheet button,
  body.mobile-mode #mobile-sheet input,
  body.mobile-mode #mobile-sheet [role="tab"] {
    touch-action: manipulation !important;
  }
  body.mobile-mode #mobile-sheet .ms-grip { display: none !important; }
  body.mobile-mode #mobile-sheet .ms-tabs { margin-bottom: 3px !important; padding: 2px !important; }
  body.mobile-mode #mobile-sheet .ms-tab { min-height: 28px !important; padding: 4px !important; font-size: 10px !important; letter-spacing: 1.2px !important; }
  body.mobile-mode #mobile-sheet .ms-row { margin-bottom: 2px !important; }
  /* Label "IMPORTO" / "CASHOUT AUTO" nascoste mobile (Stake non le mostra,
     gli input "€" e "×" hanno semantica auto-esplicativa). Recuperati ~22px. */
  body.mobile-mode #mobile-sheet .ms-label { display: none !important; }
  body.mobile-mode #mobile-sheet .ms-bet-row { margin-bottom: 2px !important; gap: 4px !important; }
  body.mobile-mode #mobile-sheet .ms-mini { min-width: 32px !important; min-height: 32px !important; font-size: 11px !important; padding: 0 3px !important; }
  body.mobile-mode #mobile-sheet .ms-input-wrap { padding: 0 8px !important; }
  body.mobile-mode #mobile-sheet .ms-input-wrap input { font-size: 13px !important; padding: 6px 0 !important; }
  body.mobile-mode #mobile-sheet .ms-toggle { min-width: 46px !important; min-height: 32px !important; font-size: 10px !important; }
  body.mobile-mode #mobile-sheet .ms-chips { gap: 3px !important; }
  body.mobile-mode #mobile-sheet .ms-chips .ms-chip {
    min-height: 26px !important;
    font-size: 10px !important;
    padding: 0 4px !important;
    flex: 1 !important;
    min-width: 0 !important;
  }
  /* CTA in fondo via flex (margin-top:auto). Stake-style: pill cilindrica grossa,
     border-radius 999 per sembrare un button "PUNTATA" rotondo, gradient ricco. */
  body.mobile-mode #mobile-sheet .ms-primary {
    min-height: 44px !important;
    margin-top: auto !important;
    font-size: 16px !important;
    font-weight: 900 !important;
    letter-spacing: 1.8px !important;
    border-radius: 999px !important;
    padding: 0 24px !important;
    background: linear-gradient(180deg, #18FF3A 0%, #00C801 60%, #008E01 100%) !important;
    box-shadow:
      0 6px 20px rgba(0,231,1,0.5),
      0 2px 6px rgba(0,231,1,0.3),
      inset 0 2px 0 rgba(255,255,255,0.35),
      inset 0 -2px 4px rgba(0,0,0,0.2) !important;
    text-shadow: 0 1px 0 rgba(255,255,255,0.2) !important;
  }
  body.mobile-mode #mobile-sheet .ms-primary:active {
    transform: scale(0.97) !important;
    box-shadow:
      0 3px 10px rgba(0,231,1,0.4),
      inset 0 2px 0 rgba(255,255,255,0.2) !important;
  }
  body.mobile-mode #mobile-sheet .ms-primary.ms-cashout {
    background: linear-gradient(180deg, #FF7A92 0%, #E0345A 60%, #B01840 100%) !important;
    box-shadow:
      0 6px 20px rgba(237,65,99,0.55),
      0 2px 6px rgba(237,65,99,0.35),
      inset 0 2px 0 rgba(255,255,255,0.3),
      inset 0 -2px 4px rgba(0,0,0,0.2) !important;
  }
  /* Stake-style: NESSUN chip preset su mobile. Né €€€ né cashout 1.5×-10×.
     L'utente cambia bet via tap su valore (apre keyboard) o ½/2×/MAX scaling.
     Recuperati ~60px verticali → sheet sta in 25vh con CTA visibile. */
  body.mobile-mode #mobile-sheet .ms-content[data-content="manual"] .ms-chips {
    display: none !important;
  }

  /* AUTO tab compressione aggressiva per stare in 200px sheet. */
  body.mobile-mode #mobile-sheet .ms-auto-grid {
    gap: 3px !important;
    margin-bottom: 3px !important;
  }
  body.mobile-mode #mobile-sheet .ms-field label {
    font-size: 8px !important;
    margin-bottom: 0 !important;
    line-height: 1 !important;
  }
  body.mobile-mode #mobile-sheet .ms-field input {
    min-height: 22px !important;
    height: 22px !important;
    padding: 1px 6px !important;
    font-size: 11px !important;
    border-radius: 6px !important;
  }
  /* AUTO btn override più piccolo (44 invece del 50 di default) per stare in 200px */
  body.mobile-mode #mobile-sheet #ms-auto-btn.ms-primary {
    min-height: 44px !important;
    font-size: 14px !important;
  }
  /* Nascosto su mobile per recuperare ~30px → AVVIA AUTO BET button visibile.
     Il giocatore vede ROUND/PROFITTO via altri indicator (es. balance pill header). */
  body.mobile-mode #mobile-sheet .ms-auto-status {
    display: none !important;
  }
  body.mobile-mode #mobile-sheet .ms-content[data-content="auto"] {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
  }
  body.mobile-mode #mobile-sheet .ms-content[data-content="auto"][hidden] {
    display: none !important;
  }
  /* STOP PROFIT / STOP LOSS: nascosti su mobile (advanced opzionali, recuperati ~50px
     per CTA "AVVIA AUTO BET" visibile). L'utente può comunque settarli da desktop. */
  body.mobile-mode #mobile-sheet #ms-sp,
  body.mobile-mode #mobile-sheet #ms-sl,
  body.mobile-mode #mobile-sheet .ms-field:has(#ms-sp),
  body.mobile-mode #mobile-sheet .ms-field:has(#ms-sl) {
    display: none !important;
  }

  /* ── Spettatore label più visibile (era piccolo grigio, ora pill giallo) ── */
  body [class*="spectator"],
  body [class*="round-status"],
  body [id*="round-status"],
  body [class*="watching"] {
    font-size: 11px !important;
    font-weight: 800 !important;
    letter-spacing: 1.2px !important;
    text-transform: uppercase !important;
    opacity: 1 !important;
    color: #FFD700 !important;
    background: rgba(255, 215, 0, 0.10) !important;
    padding: 4px 10px !important;
    border-radius: 999px !important;
    border: 1px solid rgba(255, 215, 0, 0.35) !important;
    display: inline-block !important;
  }

  /* ── Fairness hash compact su mobile (gestito anche via JS dinamico) ─ */
  body [data-fairness-hash],
  body [class*="fairness"] [class*="hash"],
  body [id*="fairness"] code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important;
    font-size: 11px !important;
    color: #00E701 !important;
    cursor: pointer !important;
  }
}

/* Tablet portrait (≤ 1024px): bilanciamento intermedio */
@media (min-width: 769px) and (max-width: 1024px) {
  body button:not([class*="close"]):not([class*="icon"]) {
    min-height: 42px !important;
  }
  body button[class*="primary"],
  body button[id*="primary"] {
    min-height: 52px !important;
    font-size: 16px !important;
  }
}

/* M2: Demo badge bottom-LEFT (era right, collide con CTA verdi) */
@media (max-width: 768px) {
  body [class*="bet-mode-banner"],
  body #bet-mode-banner,
  body [id*="demo-badge"] {
    left: 12px !important;
    right: auto !important;
    bottom: max(12px, env(safe-area-inset-bottom, 12px)) !important;
  }
}

/* M1: Hash fairness mobile più grande in monospace */
@media (max-width: 768px) {
  body [data-fairness-hash],
  body [class*="fairness"] code {
    font-size: 12px !important;
    padding: 4px 8px !important;
    background: rgba(255,255,255,0.05) !important;
    border-radius: 6px !important;
    border: 1px solid rgba(177,186,211,0.2) !important;
    cursor: pointer !important;
  }
}

/* L1: toggle non-selezionato contrast (border più chiaro su bg dark) */
@media (max-width: 768px) {
  body [class*="risk-row"] button:not(.active),
  body [class*="rows-row"] button:not(.active) {
    border: 1px solid rgba(177,186,211,0.4) !important;
    color: #DDE3F0 !important;
  }
}

/* L2: ticker mobile mid-spin nascosto (consuma 24px senza valore primario) */
@media (max-width: 414px) {
  body[class*="running"] [class*="live-wins-ticker"],
  body [id*="ticker"][class*="hidden-mid-spin"] {
    display: none !important;
  }
}

/* L3: 🏆 trofeo con tooltip "Classifica" via title attribute (gestito JS) */
@media (max-width: 768px) {
  body [class*="trophy"]::after,
  body [data-tab="lb"]::after {
    content: '' !important;
  }
}

/* Mines mobile FIX H5: BET button sotto fold iPhone SE (375×667).
   Su mobile portrait, MAI permettere overflow: comprimi sezioni intermedie.
   Quick chips €€€ + preset MINE 1/3/5/10/24 raddoppiavano altezza.
   Soluzione: nascondo quick chips €€€ su mobile (Stake-style: solo MIN/½/2×/MAX). */
@media (max-width: 768px) {
  body[class*="mines"] [class*="chip-row-amount"],
  body canvas + #autobet-panel {
    /* Hook for Mines quick chips €€€ — selector approssimativo, va calibrato */
  }
}

/* iPad portrait (768×1024) FIX BLOCKER B1:
   il layout desktop ha sidebar 120px → label compressi 7-9px illeggibili.
   Forzo display stacked verticale come mobile, con padding generoso.
   Trigger: orientation portrait + width 768-1024. */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  body { font-size: 14px !important; }
  body canvas { max-height: 60vh !important; }
  body #autobet-panel,
  body [class*="bet-panel"][class*="side"],
  body [id*="ctrl-panel"] {
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
  }
  body [class*="-panel"] [class*="-label"],
  body [class*="-panel"] label {
    font-size: 13px !important;
  }
  body [class*="fairness"] code,
  body [data-fairness-hash] {
    font-size: 13px !important;
  }
}

/* Desktop laptop 1366×768 FIX H1: bet panel font sotto 12px.
   Forza min-font 12 su tutti i label nel pannello bet desktop sotto 1440. */
@media (min-width: 1025px) and (max-width: 1440px) {
  body [class*="ctrl"] [class*="label"],
  body [class*="bet-panel"] label,
  body [class*="ms-label"] {
    font-size: 12px !important;
  }
  body code,
  body [data-fairness-hash] {
    font-size: 12px !important;
  }
}
