/* ═══════════════════════════════════════════════════════════════
   MIDNIGHT BLACKJACK — main.css (FASE 1)
   Layout mobile-first verticale, solo CSS (nessun asset grafico).
   I token (colori, misure) stanno in tokens.css.
   ═══════════════════════════════════════════════════════════════ */

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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--c-night);
  color: var(--c-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;              /* su desktop l'app resta "da telefono" */
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Schermate ─────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  width: 100%;
  flex: 1;
  min-height: 0;
}
.screen.active { display: flex; }

/* Lobby: blu notte con texture diagonale sottile */
#screen-home {
  background:
    repeating-linear-gradient(115deg, rgba(255,255,255,.016) 0 2px, transparent 2px 9px),
    radial-gradient(140% 100% at 50% 0%, #101830 0%, var(--c-night) 70%);
}

/* Tavolo: feltro verde con vignetta radiale */
#screen-table {
  background:
    radial-gradient(130% 95% at 50% 28%, var(--c-felt) 0%, var(--c-felt-dark) 72%, #062417 100%);
}

/* ── HUD superiore ─────────────────────────────────────────── */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
}
.hud-spacer { width: 42px; }
.hud-title {
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 700;
  color: rgba(244,241,232,.55);
  text-align: center;
}
.hud-balance {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(0,0,0,.38);
  border: 1px solid rgba(232,182,76,.45);
  border-radius: 999px;
  padding: 5px 12px 5px 7px;
  font-weight: 800;
  font-size: 15px;
  color: var(--c-gold-light);
}

/* Gettone "coin" disegnato in CSS puro */
.coin {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #FFE9A8, #E8B64C 58%, #8A6420);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.28), 0 1px 2px rgba(0,0,0,.5);
  flex: none;
}
.coin-lg { width: 44px; height: 44px; }

/* ── Pulsanti ──────────────────────────────────────────────── */
.btn {
  border: none;
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #fff;
  border-radius: var(--radius);
  height: var(--btn-h);
  padding: 0 18px;
  min-width: 64px;
  transition: transform .08s ease, filter .12s ease;
}
.btn:active { transform: translateY(3px); filter: brightness(1.08); }
.btn:disabled { opacity: .38; pointer-events: none; }

.btn-gold {
  background: linear-gradient(180deg, var(--c-gold-light), var(--c-gold));
  color: #3A2A08;
  box-shadow: 0 4px 0 var(--c-gold-dark);
}
.btn-red {
  background: linear-gradient(180deg, #F05555, var(--c-red));
  box-shadow: 0 4px 0 var(--c-red-dark);
}
.btn-dark {
  background: linear-gradient(180deg, #2A3452, var(--c-panel-2));
  border: 1px solid #3D4A78;
  box-shadow: 0 4px 0 #0D1322;
}
.btn-gold-outline {
  background: rgba(232,182,76,.10);
  border: 2px solid var(--c-gold);
  color: var(--c-gold-light);
}
.btn-ghost {
  background: rgba(255,255,255,.09);
  color: var(--c-text-dim);
  box-shadow: 0 4px 0 rgba(0,0,0,.30);
}
.btn-xl {
  height: 66px;
  font-size: 20px;
  width: min(78%, 300px);
}
.btn-icon {
  width: 42px;
  height: 42px;
  min-width: 0;
  border-radius: 12px;
  font-size: 24px;
  line-height: 1;
  padding: 0;
  background: rgba(0,0,0,.35);
  color: var(--c-text);
  box-shadow: none;
  border: 1px solid rgba(255,255,255,.14);
}

/* ── HOME ──────────────────────────────────────────────────── */
.home-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 12px 24px calc(20px + env(safe-area-inset-bottom));
}
.logo { text-align: center; }
.logo-suits { font-size: 22px; letter-spacing: 8px; margin-bottom: 10px; }
.logo-suits span { color: #D8DCEA; }
.logo-suits .red { color: #E25B5B; }
.logo-title {
  font-size: clamp(34px, 10vw, 46px);
  line-height: 1.04;
  font-weight: 900;
  letter-spacing: 3px;
  background: linear-gradient(180deg, #FFD873 20%, #E8B64C 55%, #A87C22 95%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 1px rgba(0,0,0,.55));
}
.logo-tagline {
  margin-top: 10px;
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--c-text-dim);
}
.home-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--c-panel);
  border: 1px solid #2A3452;
  border-radius: var(--radius);
  padding: 14px 24px;
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
}
.home-card-label {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--c-text-dim);
  font-weight: 700;
}
.home-card-value {
  font-size: 26px;
  font-weight: 900;
  color: var(--c-gold-light);
}
.home-foot {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #55607A;
  text-align: center;
}

/* ── TAVOLO ────────────────────────────────────────────────── */
.hand-label {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 3px;
  color: rgba(244,241,232,.72);
  padding: 6px 0 2px;
}
.score {
  display: inline-block;
  min-width: 34px;
  text-align: center;
  background: rgba(0,0,0,.42);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  padding: 2px 7px;
  margin-left: 6px;
  font-size: 13px;
  color: var(--c-gold-light);
}
.cards {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(var(--card-h) + 10px);
  padding: 2px 0;
}

/* Messaggi centrali (suggerimenti ed esito del round) */
.table-message {
  flex: 1;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 14px;
}
.table-hint {
  font-size: 12px;
  letter-spacing: 3px;
  font-weight: 700;
  color: rgba(244,241,232,.55);
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
.result {
  text-align: center;
  animation: pop-in .38s cubic-bezier(.2,1.6,.4,1) backwards;
}
.result-title {
  font-size: clamp(28px, 8vw, 38px);
  font-weight: 900;
  letter-spacing: 3px;
  text-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.result-sub {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
}
.result.win .result-title,
.result.blackjack .result-title { color: var(--c-gold-light); }
.result.win .result-sub,
.result.blackjack .result-sub { color: var(--c-green); }
.result.lose .result-title { color: #F26D6D; }
.result.lose .result-sub { color: #F0A3A3; }
.result.push .result-title { color: #C9D0E0; }
.result.push .result-sub { color: var(--c-text-dim); }
@keyframes pop-in {
  from { transform: scale(.5); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ── Carte ─────────────────────────────────────────────────── */
.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 12px;
  background: linear-gradient(160deg, #FFFDF6 0%, #F1EDDF 100%);
  color: var(--c-ink);
  position: relative;
  box-shadow: 0 3px 8px rgba(0,0,0,.45), inset 0 0 0 1px rgba(0,0,0,.10);
  margin-left: calc(var(--card-w) * -0.28); /* sovrapposizione a ventaglio */
  flex: none;
}
.card:first-child { margin-left: 0; }
/* Con 5+ carte in mano la sovrapposizione aumenta per non uscire dallo schermo */
.cards:has(.card:nth-child(n+5)) .card { margin-left: calc(var(--card-w) * -0.5); }
.cards:has(.card:nth-child(n+5)) .card:first-child { margin-left: 0; }
.card.red { color: #BE3A3A; }
.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 800;
}
.corner.top { top: 5px; left: 6px; }
.corner.bottom { bottom: 5px; right: 6px; transform: rotate(180deg); }
.corner .rank { font-size: calc(var(--card-w) * 0.30); }
.corner .suit { font-size: calc(var(--card-w) * 0.24); margin-top: 1px; }
.pip {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.58);
}
/* Dorso della carta: pattern oro su blu notte */
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(232,182,76,.16) 0 5px, transparent 5px 10px),
    linear-gradient(160deg, #1B2A5E, #131C40);
  box-shadow:
    0 3px 8px rgba(0,0,0,.45),
    inset 0 0 0 3px #F1EDDF,
    inset 0 0 0 4px #8A6420;
}
/* Animazione di distribuzione */
.card.deal { animation: deal-in .34s cubic-bezier(.2,1.2,.4,1) backwards; }
@keyframes deal-in {
  from { transform: translateY(-46px) rotate(-7deg); opacity: 0; }
  to   { transform: translateY(0) rotate(0); opacity: 1; }
}

/* ── Barra azioni / puntata ────────────────────────────────── */
.action-bar {
  padding: 8px 14px calc(14px + env(safe-area-inset-bottom));
}
.phase {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.phase.hidden, .hidden { display: none !important; }

.bet-display {
  text-align: center;
  font-weight: 900;
  letter-spacing: 2px;
  font-size: 15px;
  color: var(--c-gold-light);
}
.bet-display .bet-value {
  font-size: 24px;
  margin-left: 8px;
}
.chip-tray {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.chip {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font: inherit;
  position: relative;
  box-shadow: 0 4px 0 rgba(0,0,0,.4), inset 0 0 0 3px rgba(255,255,255,.85);
  transition: transform .08s ease;
}
.chip::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 2px dashed rgba(255,255,255,.75);
}
.chip:active { transform: translateY(3px); }
.chip:disabled { opacity: .35; pointer-events: none; }
.chip-value {
  position: relative;
  font-weight: 900;
  font-size: 16px;
}
.chip-1   { background: var(--chip-1);   color: #3A372C; }
.chip-5   { background: var(--chip-5);   color: #fff; }
.chip-10  { background: var(--chip-10);  color: #fff; }
.chip-50  { background: var(--chip-50);  color: #fff; }
.chip-100 { background: var(--chip-100); color: var(--c-gold-light); }

.bet-actions { display: flex; gap: 10px; }
.bet-actions .btn,
#phase-player .btn { flex: 1; }
#phase-player { flex-direction: row; gap: 10px; }
#btn-topup { margin-top: 10px; }

/* ═══════════════════════════════════════════════════════════════
   MOCK VIDEO AD (FASE 2) — overlay a schermo intero che simula un
   video: countdown, barra di avanzamento, chiusura solo a fine video.
   Il banner è un placeholder fisso in basso.
   ═══════════════════════════════════════════════════════════════ */
.ad-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #06080F;
  display: flex;
  flex-direction: column;
  padding: calc(6px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  animation: ad-fade .25s ease-out;
}
.ad-overlay.hidden { display: none; }
@keyframes ad-fade { from { opacity: 0; } to { opacity: 1; } }

.ad-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}
.ad-badge {
  background: var(--c-gold);
  color: #3A2A08;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 6px;
}
.ad-countdown {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--c-text-dim);
  font-variant-numeric: tabular-nums;
}
.ad-close {
  margin-left: auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.08);
  color: var(--c-text);
  font-size: 17px;
  cursor: pointer;
}
.ad-close:disabled { opacity: .3; }

/* Area "video": gradiente in movimento + semi fluttuanti */
.ad-video {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, #131C40, #1E2B5A, #131C40);
  background-size: 200% 100%;
  animation: ad-slide 3.5s linear infinite;
  overflow: hidden;
  min-height: 0;
}
@keyframes ad-slide {
  from { background-position: 0% 0; }
  to   { background-position: 200% 0; }
}
.ad-suits span {
  font-size: 44px;
  color: #D8DCEA;
  display: inline-block;
  margin: 0 8px;
  animation: ad-float 2.4s ease-in-out infinite;
}
.ad-suits span:nth-child(2) { animation-delay: .3s; }
.ad-suits span:nth-child(3) { animation-delay: .6s; }
.ad-suits span:nth-child(4) { animation-delay: .9s; }
.ad-suits .red { color: #E25B5B; }
@keyframes ad-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
.ad-headline {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--c-gold-light);
  text-align: center;
}
.ad-sub {
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--c-text-dim);
  text-align: center;
}

.ad-progress {
  height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,.12);
  margin: 14px 0;
  overflow: hidden;
}
.ad-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--c-gold), var(--c-gold-light));
}
.ad-cta { width: 100%; }

/* Banner mock in basso */
.ad-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(8px + env(safe-area-inset-bottom));
  width: min(100% - 24px, 464px);
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,14,26,.92);
  border: 1px dashed rgba(232,182,76,.55);
  border-radius: 10px;
  color: var(--c-text-dim);
  font-size: 11px;
  letter-spacing: 2px;
  z-index: 900;
}
.ad-banner.hidden { display: none; }
