:root {
  --bg: radial-gradient(circle at 30% 30%, #1b2740, #090d15 60%);
  --panel: linear-gradient(145deg, #0f1728, #1a2440);
  --accent: #3ad4ff;
  --accent-2: #ff8f3a;
  --win: #ffe36c;
  --lose: #c1ccda;
  --text: #dfe8ff;
  --cell-size: 78px;
  --gap: 6px;
  --drop: 14px;
  --spin-time: 1.4s;
  --spin-time-turbo: 0.7s;
  --shadow: 0 12px 32px rgba(0,0,0,0.55);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}

.app {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

@media (min-width: 901px) {
  .app { zoom: 0.8; }
}

.ui-top { display:flex; gap:10px; width:100%; justify-content:center; }
.badge { background:rgba(255,255,255,0.08); border:1px solid rgba(255,255,255,0.12); padding:6px 10px; border-radius:12px; box-shadow: var(--shadow); font-weight:600; }
#turboBadge { opacity:0; transition:0.2s; }
#multBadge { transition: opacity 0.2s ease; }
#multBadge.bump { animation: multBump 0.5s cubic-bezier(.16,1.2,.3,1) both; }

@keyframes multBump {
  0% { transform: scale(0.92); filter: brightness(1); box-shadow: var(--shadow); }
  35% { transform: scale(1.08); filter: brightness(1.25); box-shadow: 0 0 24px rgba(255,224,112,0.5), var(--shadow); }
  70% { transform: scale(0.98); filter: brightness(1.1); box-shadow: 0 0 14px rgba(255,224,112,0.35), var(--shadow); }
  100% { transform: scale(1); filter: brightness(1); box-shadow: var(--shadow); }
}

.big-win {
  width: min(1000px, 96vw);
  display: grid;
  place-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.05);
  box-shadow: var(--shadow);
}
.big-win-label {
  font-weight: 800;
  letter-spacing: 0.18em;
  opacity: 0.8;
  font-size: 12px;
}
.big-win-value {
  font-weight: 900;
  font-size: clamp(28px, 5vw, 46px);
  line-height: 1.05;
  color: #fff1a6;
  text-shadow: 0 3px 10px rgba(0,0,0,0.5), 0 0 22px rgba(255,224,112,0.35);
}
.big-win.bump .big-win-value { animation: bigWinBump 0.55s cubic-bezier(.16,1.2,.3,1) both; }
@keyframes bigWinBump {
  0% { transform: scale(0.92); filter: brightness(1); }
  40% { transform: scale(1.10); filter: brightness(1.25); }
  100% { transform: scale(1); filter: brightness(1); }
}

.mult-side {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: min(180px, 18vw);
  padding: 14px 12px;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.18);
  background: linear-gradient(145deg, rgba(255,255,255,0.06), rgba(0,0,0,0.2));
  box-shadow:
    inset 0 2px 8px rgba(255,255,255,0.12),
    inset 0 -4px 12px rgba(0,0,0,0.45),
    0 18px 36px rgba(0,0,0,0.55);
  z-index: 3;
  opacity: 0;
  pointer-events: none;
}
.mult-side.on { opacity: 1; }
.mult-side.bump { animation: multSideBump 0.5s cubic-bezier(.16,1.2,.3,1) both; }
.mult-side-title {
  font-family: Impact, Haettenschweiler, "Arial Black", system-ui, sans-serif;
  font-weight: 900;
  letter-spacing: 0.14em;
  font-size: 14px;
  opacity: 0.85;
  text-align: center;
}
.mult-side-value {
  font-family: Impact, Haettenschweiler, "Arial Black", system-ui, sans-serif;
  font-weight: 900;
  text-align: center;
  font-size: clamp(36px, 4.2vw, 54px);
  color: #ffe070;
  text-shadow: 0 3px 10px rgba(0,0,0,0.55), 0 0 24px rgba(255,208,120,0.45);
  margin-top: 6px;
}
@keyframes multSideBump {
  0% { transform: translateY(-50%) scale(0.94); filter: brightness(1); }
  40% { transform: translateY(-50%) scale(1.07); filter: brightness(1.25); }
  100% { transform: translateY(-50%) scale(1); filter: brightness(1); }
}

.bonus-side {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: min(260px, 24vw);
  padding: 14px 12px;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.18);
  background: linear-gradient(145deg, rgba(255,255,255,0.06), rgba(0,0,0,0.2));
  box-shadow:
    inset 0 2px 8px rgba(255,255,255,0.12),
    inset 0 -4px 12px rgba(0,0,0,0.45),
    0 18px 36px rgba(0,0,0,0.55);
  z-index: 3;
  opacity: 0;
  pointer-events: none;
}
.bonus-side.on { opacity: 1; }
.bonus-side-title {
  font-family: Impact, Haettenschweiler, "Arial Black", system-ui, sans-serif;
  font-weight: 900;
  letter-spacing: 0.12em;
  font-size: 14px;
  opacity: 0.85;
  text-align: center;
}
.bonus-side-total {
  font-family: Impact, Haettenschweiler, "Arial Black", system-ui, sans-serif;
  font-weight: 900;
  text-align: center;
  font-size: clamp(26px, 3.3vw, 38px);
  color: #fff1a6;
  text-shadow: 0 3px 10px rgba(0,0,0,0.55), 0 0 22px rgba(255,224,112,0.35);
  margin-top: 6px;
}
.bonus-side-subtitle {
  margin-top: 10px;
  font-weight: 800;
  font-size: 12px;
  opacity: 0.75;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
}
.bonus-breakdown {
  margin-top: 8px;
  display: grid;
  gap: 6px;
  max-height: min(360px, 46vh);
  overflow: hidden;
}
.bonus-breakdown-empty {
  text-align: center;
  opacity: 0.65;
  font-weight: 700;
  font-size: 12px;
  padding: 10px 6px;
}
.bonus-row {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  box-shadow: inset 0 1px 3px rgba(255,255,255,0.10);
  color: rgba(223,232,255,0.96);
}

.game-shell {
  position: relative;
  width: min(1100px, 92vw);
  aspect-ratio: 1/1; /* taller cabinet */
  background: var(--panel);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.glow-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 60%, rgba(58,212,255,0.15), transparent 55%),
              radial-gradient(circle at 40% 30%, rgba(255,143,58,0.18), transparent 45%);
  filter: blur(10px);
  pointer-events: none;
  z-index: 0;
}

#slotCabinet {
  position: relative;
  width: 90%;
  height: 85%;
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0)),
              linear-gradient(145deg, #0d1425, #0b0f19 55%, #0d1425);
  border: 3px solid rgba(255,255,255,0.16);
  border-radius: 18px;
  box-shadow:
    inset 0 2px 6px rgba(255,255,255,0.16),
    inset 0 -3px 8px rgba(0,0,0,0.55),
    0 18px 40px rgba(0,0,0,0.6);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 10px;
}

#reels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
  height: 100%;
  align-items: end;
}

.reel {
  position: relative;
  background: linear-gradient(200deg, rgba(255,255,255,0.08), rgba(0,0,0,0.28));
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    inset 0 1px 4px rgba(255,255,255,0.22),
    inset 0 -2px 6px rgba(0,0,0,0.45),
    0 10px 24px rgba(0,0,0,0.45);
  height: 100%;
}

.reel .symbols {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: var(--rows-template, repeat(7, 1fr));
  align-items: stretch;
  justify-items: center;
  gap: var(--gap, 6px);
  padding: 6px 4px;
  transition: transform 0.22s cubic-bezier(.3,1.5,.6,1), opacity 0.14s ease, filter 0.14s ease;
}
.reel.spinning .symbols { opacity: 0; filter: blur(0); }
.reel.kick .symbols { animation: kick 0.24s cubic-bezier(.25, .7, .4, 1.02); }

.symbol {
  width: 90%;
  height: 100%; /* riempi l'intera cella */
  overflow: hidden; /* crop se eccede */
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  align-self: center;
  position: relative;
  background: rgba(255,255,255,0.03);
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.35),
    inset 0 -3px 7px rgba(0,0,0,0.45),
    0 3px 8px rgba(0,0,0,0.45),
    0 10px 18px rgba(0,0,0,0.35);
  border: 2px solid rgba(255,255,255,0.34);
}

.symbol-face {
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center center;
  will-change: transform;
  transform-origin: center center;
}

/* sprite images */
.symbol-face.A { background-image: url('images/split/A.png?v=2'); }
.symbol-face.B { background-image: url('images/split/B.png'); }
.symbol-face.C { background-image: url('images/split/C.png'); }
.symbol-face.D { background-image: url('images/split/D.png'); }
.symbol-face.E { background-image: url('images/split/E.png'); }
.symbol-face.F { background-image: url('images/split/F.png'); }
.symbol-face.W { background-image: url('images/split/W.png'); }
.symbol-face.S { background-image: url('images/split/S.png'); }
.symbol-face.G { background-image: url('images/split/G.png'); }
.symbol-face.P { background-image: url('images/bonus-point.png'); }

/* tonalità di sfondo per aiutare il contrasto */
.symbol.A { background-color: rgba(255, 204, 92, 0.25); }
.symbol.B { background-color: rgba(110, 231, 255, 0.25); }
.symbol.C { background-color: rgba(217, 139, 255, 0.25); }
.symbol.D { background-color: rgba(138, 250, 181, 0.25); }
.symbol.E { background-color: rgba(255, 159, 177, 0.25); }
.symbol.F { background-color: rgba(255, 200, 255, 0.25); }
.symbol.G { background-color: rgba(255, 230, 140, 0.25); }
.symbol.P { background-color: rgba(255, 230, 140, 0.35); }
.symbol.W { background-color: rgba(255, 246, 163, 0.35); }
.symbol.S { background-color: rgba(255, 112, 58, 0.35); }

.reel .spin-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: repeat(var(--overlay-length, 14), 1fr);
  align-items: stretch;
  justify-items: center;
  gap: var(--gap, 6px);
  padding: 6px 4px;
  animation: spin-scroll-down var(--spin-speed, 0.16s) var(--spin-ease, linear) infinite;
  filter: blur(4px) brightness(1.1) saturate(1.05);
  opacity: 0.9;
  transform: translateZ(0) scaleY(1.05); /* force GPU + directional stretch */
  mask-image: linear-gradient(180deg, transparent 0%, rgba(255,255,255,0.4) 12%, rgba(255,255,255,0.9) 50%, rgba(255,255,255,0.4) 88%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, transparent 0%, rgba(255,255,255,0.4) 12%, rgba(255,255,255,0.9) 50%, rgba(255,255,255,0.4) 88%, transparent 100%);
  transition: opacity 0.12s ease;
}

@keyframes spin-scroll-down {
  from { transform: translateY(0); }
  to { transform: translateY(50%); }
}

@keyframes kick {
  0% { transform: translateY(0); }
  28% { transform: translateY(-8px); }
  65% { transform: translateY(10px); }
  100% { transform: translateY(2px); }
}

.reel.spinning::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, transparent, rgba(0,0,0,0.25) 25%, rgba(0,0,0,0.35) 75%, transparent);
  pointer-events: none;
}

.reel.anticipation {
  /* gold anticipation (no red) */
  box-shadow: 0 0 24px rgba(255,224,112,0.55), inset 0 0 0 2px rgba(255,224,112,0.28);
}
.reel.tease {
  animation: teaseShake 0.085s linear infinite;
  will-change: transform;
  transform-origin: 50% 50%;
  filter: drop-shadow(0 0 14px rgba(255,160,80,0.25));
}

@keyframes teaseShake {
  0% { transform: translate3d(0,0,0) rotateZ(0deg); }
  20% { transform: translate3d(6px,-4px,0) rotateZ(2.0deg); }
  40% { transform: translate3d(-6px,4px,0) rotateZ(-2.0deg); }
  60% { transform: translate3d(4px,0,0) rotateZ(1.2deg); }
  80% { transform: translate3d(-4px,0,0) rotateZ(-1.2deg); }
  100% { transform: translate3d(0,0,0) rotateZ(0deg); }
}

.symbol.win .symbol-face { animation: winPop 0.9s ease-out 0s 2 alternate; }
@keyframes winPop {
  0%   { transform: scale(0.96); }
  55%  { transform: scale(1.08); }
  100% { transform: scale(1.0); }
}

/* Bonus point (+1 spin) ghost + float label */
.symbol.bonus-pop .symbol-face {
  animation: bonusGhost 0.9s ease-out both;
}
@keyframes bonusGhost {
  0% { filter: blur(0px) brightness(1); opacity: 1; }
  30% { filter: blur(0.8px) brightness(1.4); opacity: 0.95; }
  100% { filter: blur(2.2px) brightness(1.1); opacity: 0.65; }
}
.bonus-float {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  font-family: Impact, Haettenschweiler, "Arial Black", system-ui, sans-serif;
  font-weight: 900;
  font-size: clamp(16px, 2.2vw, 22px);
  letter-spacing: 0.06em;
  color: #fff1a6;
  text-shadow: 0 2px 8px rgba(0,0,0,0.55), 0 0 18px rgba(255,208,120,0.45);
  pointer-events: none;
  opacity: 0;
  animation: bonusFloat 0.95s ease-out forwards;
}
@keyframes bonusFloat {
  0% { opacity: 0; transform: translate(-50%, -35%) scale(0.92); }
  20% { opacity: 1; transform: translate(-50%, -55%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -105%) scale(1.02); }
}

.controls, .hud {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: min(1000px, 96vw);
}

.controls button, .hud button, select {
  background: linear-gradient(145deg, #1e2a4a, #263561);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.controls button:active { transform: translateY(2px) scale(0.98); filter: brightness(0.9); }

.controls .primary { background: linear-gradient(145deg, #3ad4ff, #1da8ff); color: #0c1322; }
.controls .muted { opacity: 0.75; }

.stat { background: rgba(255,255,255,0.06); padding: 8px 12px; border-radius: 10px; border:1px solid rgba(255,255,255,0.08); box-shadow: var(--shadow); }

.toggle { display:flex; align-items:center; gap:6px; background: rgba(255,255,255,0.06); padding: 6px 10px; border-radius: 10px; border:1px solid rgba(255,255,255,0.08); box-shadow: var(--shadow); }

#fxCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30; /* above cabinet/reels, below modal */
}

/* Modal Free Spins */
.modal.hidden { display: none; }
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 40;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
}
.modal-card {
  position: relative;
  z-index: 1;
  background: linear-gradient(145deg, #0f1527, #16203a);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.65), inset 0 2px 8px rgba(255,255,255,0.12);
  padding: 18px;
  width: min(520px, 90vw);
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 14px;
  transform: scale(0.86);
  animation: modalIn 0.22s ease-out forwards;
}
.modal-art {
  width: 100%;
  aspect-ratio: 4/5;
  border-radius: 14px;
  background: url('images/free-spins.png') center center / cover no-repeat;
  box-shadow: inset 0 2px 8px rgba(255,255,255,0.18), inset 0 -4px 10px rgba(0,0,0,0.35), 0 8px 24px rgba(0,0,0,0.5);
}
.modal-body { display: grid; gap: 10px; align-content: center; }
.modal-title { font-size: clamp(26px, 3vw, 32px); font-weight: 800; color: #fff6c0; }
.modal-sub { font-size: 18px; color: #cfe1ff; }

@keyframes modalIn {
  from { transform: scale(0.86); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

@media (max-width: 900px) {
  :root { --cell-size: 64px; }
  .game-shell { aspect-ratio: 1/1; }
}
