/* ══════════════════════════════════════════════════════════════════
   ASTRO TETRIS — style.css
   Palette: arancio #ff6b1a  |  cyan #1ab8ff  |  bianco #f5f0e8
   ══════════════════════════════════════════════════════════════════ */

/* ── VARIABILI GLOBALI ─────────────────────────────────────────── */
:root {
  --arancio   : #ff6b1a;
  --cyan      : #1ab8ff;
  --bianco    : #f5f0e8;
  --nero      : #000000;

  --pannello  : rgba(0, 0, 0, 0.72);
  --bordo-a   : rgba(255, 107, 26, 0.5);
  --bordo-c   : rgba(26, 184, 255, 0.4);
  --glow-a    : rgba(255, 107, 26, 0.7);
  --glow-c    : rgba(26, 184, 255, 0.7);
  --raggio-card      : 20px;
  --raggio-controllo : 14px;
  --raggio-cella     : 6px;
  --raggio-pill      : 999px;

  /* Sfondo animato — modificate via JS con applicaPalette() */
  --bg-c1     : #000000;
  --bg-c2     : #0a0515;
  --bg-c3     : #1ab8ff;
  --bg-c4     : #ff6b1a;
  --bg-angle  : 135deg;
  --onda-a    : rgba(26,184,255,.24);
  --onda-b    : rgba(255,107,26,.20);
  --menu-accent-a : #1ab8ff;
  --menu-accent-b : #ff6b1a;
  --menu-glow-a   : rgba(26,184,255,.62);
  --menu-glow-b   : rgba(255,107,26,.58);
  transition  :
    --onda-a 2s ease,
    --onda-b 2s ease,
    --menu-accent-a 1.8s ease,
    --menu-accent-b 1.8s ease,
    --menu-glow-a 1.8s ease,
    --menu-glow-b 1.8s ease;
}

@font-face {
  font-family: 'Planet Kosmos';
  src: url('fonts/PLANK___.TTF') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@property --onda-a {
  syntax: '<color>';
  inherits: true;
  initial-value: rgba(26,184,255,.24);
}

@property --onda-b {
  syntax: '<color>';
  inherits: true;
  initial-value: rgba(255,107,26,.20);
}

@property --menu-accent-a {
  syntax: '<color>';
  inherits: true;
  initial-value: #1ab8ff;
}

@property --menu-accent-b {
  syntax: '<color>';
  inherits: true;
  initial-value: #ff6b1a;
}

@property --menu-glow-a {
  syntax: '<color>';
  inherits: true;
  initial-value: rgba(26,184,255,.62);
}

@property --menu-glow-b {
  syntax: '<color>';
  inherits: true;
  initial-value: rgba(255,107,26,.58);
}

/* ── RESET ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing : border-box;
  margin     : 0;
  padding    : 0;
}

/* ══════════════════════════════════════════════════════════════════
   BODY — sfondo gradiente animato con cambio palette via JS
   ══════════════════════════════════════════════════════════════════ */
body {
  height      : 100vh;
  height      : 100dvh;
  width       : 100%;
  overflow    : hidden;
  color       : var(--bianco);
  font-family : 'Share Tech Mono', monospace;
  cursor      : crosshair;

  background  : #02030a;
}

/* ── GRAIN / NOISE — texture animata sovrapposta al body ────────── */
#sfondoSpaziale {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(ellipse var(--fallback-size-a, 72% 62%) at var(--fallback-pos-a, 27% 40%), var(--onda-a), transparent 74%),
    radial-gradient(ellipse var(--fallback-size-b, 68% 58%) at var(--fallback-pos-b, 78% 66%), var(--onda-b), transparent 76%),
    linear-gradient(145deg, #030108 0%, #080612 55%, #02030a 100%);
}

body.astro-engine-aether #sfondoSpaziale {
  background:
    radial-gradient(ellipse var(--fallback-size-b, 68% 58%) at var(--fallback-pos-b, 78% 66%), var(--onda-b), transparent 68%),
    radial-gradient(ellipse var(--fallback-size-a, 72% 62%) at var(--fallback-pos-a, 27% 40%), var(--onda-a), transparent 74%),
    radial-gradient(ellipse at 50% 45%, rgba(36, 59, 105, .18), transparent 70%),
    linear-gradient(155deg, #03040d 0%, #07101d 52%, #03030b 100%);
}

body.astro-scene-horizon #sfondoSpaziale {
  background:
    radial-gradient(ellipse at 54% 49%, #01020a 0 9%, transparent 10% 18%, rgba(64, 120, 255, .25) 19%, transparent 27%),
    conic-gradient(from 220deg at 53% 50%, transparent 0 17%, rgba(255, 73, 63, .18) 20%, rgba(255, 230, 202, .34) 22%, rgba(48, 113, 255, .2) 26%, transparent 34%),
    radial-gradient(ellipse at 53% 50%, #030512 0 16%, #090b21 44%, #03040d 78%);
}

body.astro-scene-nebula #sfondoSpaziale {
  background:
    radial-gradient(ellipse at 36% 48%, rgba(34, 101, 255, .32), transparent 42%),
    radial-gradient(ellipse at 64% 54%, rgba(139, 44, 231, .28), transparent 47%),
    radial-gradient(ellipse at 52% 40%, rgba(38, 221, 235, .14), transparent 34%),
    #03040d;
}

body.astro-scene-tunnel #sfondoSpaziale {
  background:
    repeating-radial-gradient(ellipse at 51% 48%, transparent 0 8%, rgba(41, 146, 255, .13) 9%, transparent 10% 17%),
    radial-gradient(ellipse at 50% 50%, #061126 0, #03040d 62%, #010208 100%);
}

body.astro-scene-spiral #sfondoSpaziale {
  background:
    conic-gradient(from 20deg at 50% 50%, transparent 0 9%, rgba(44, 127, 255, .18) 12%, transparent 21% 35%, rgba(161, 68, 245, .16) 40%, transparent 48% 68%, rgba(45, 193, 255, .13) 75%, transparent 82%),
    radial-gradient(ellipse at center, #10102b 0, #050511 43%, #02030a 78%);
}

body.astro-scene-collapse #sfondoSpaziale {
  background:
    radial-gradient(ellipse at 50% 50%, transparent 0 15%, rgba(56, 125, 255, .16) 20%, transparent 24% 34%, rgba(255, 85, 74, .14) 39%, transparent 44% 55%, rgba(74, 125, 255, .12) 60%, transparent 66%),
    radial-gradient(ellipse at center, #080816, #02030a 72%);
}

#astroBackground {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity .35s ease;
}

body.astro-background-ready #astroBackground { opacity: .88; }

#astroOverlay {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(ellipse at center, transparent 35%, rgba(0,0,0,.38) 100%),
    linear-gradient(180deg, rgba(0,0,0,.12), transparent 25%, transparent 75%, rgba(0,0,0,.2));
  pointer-events: none;
}

#astroGrain {
  position: absolute;
  inset: 0;
  z-index: 2;
  opacity: .035;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

body.astro-webgl-unavailable #astroBackground { display: none; }
body::after {
  content    : "";
  position   : fixed;
  inset      : 0;
  z-index    : 2;
  background : repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0.055) 0px,
    rgba(0,0,0,0.055) 1px,
    transparent      1px,
    transparent      5px
  );
  pointer-events : none;
  transition : opacity 0.3s;
}
body.senza-scanlines::after { opacity: 0; }

/* ── OVERLAY INTENSITÀ SFONDO — oscura lo sfondo animato ────────── */
#overlayIntensita {
  position       : fixed;
  inset          : 0;
  z-index        : 3;
  background     : #000;
  opacity        : 0;
  pointer-events : none;
  transition     : opacity 0.3s;
}

/* ── FLICKER OVERLAY — flash colorato su level-up e drop ────────── */
#flickerOverlay {
  position       : fixed;
  inset          : 0;
  z-index        : 25;
  background     : transparent;
  opacity        : 0;
  pointer-events : none;
  mix-blend-mode : screen;
}

/* ══════════════════════════════════════════════════════════════════
   EFFETTO GLITCH — testo (usato su titoli e banner)
   ══════════════════════════════════════════════════════════════════ */
.glitch-text {
  position : relative;
}
.glitch-text::before,
.glitch-text::after {
  content        : attr(data-text);
  position       : absolute;
  top            : 0;
  left           : 0;
  right          : 0;
  overflow       : hidden;
  pointer-events : none;
}
.glitch-text::before {
  animation  : glitch-clip-a 4s infinite;
  color      : #ff006e;
  left       : 3px;
  opacity    : 0.85;
}
.glitch-text::after {
  animation  : glitch-clip-b 4s infinite;
  color      : #1ab8ff;
  left       : -3px;
  opacity    : 0.85;
}

@keyframes glitch-clip-a {
  0%,92%,100% { clip-path: inset(100% 0 0 0); transform: translate(0); }
  5%  { clip-path: inset(15% 0 65% 0); transform: translate(-4px,0) skewX(-4deg); }
  8%  { clip-path: inset(55% 0 20% 0); transform: translate( 4px,0) skewX( 2deg); }
  11% { clip-path: inset(35% 0 45% 0); transform: translate(-2px,0); }
  14% { clip-path: inset(100% 0 0 0);  transform: translate(0); }
  41% { clip-path: inset(5%  0 80% 0); transform: translate( 5px,0) skewX(3deg); }
  42% { clip-path: inset(100% 0 0 0);  transform: translate(0); }
  71% { clip-path: inset(45% 0 30% 0); transform: translate(-3px,0) skewX(-2deg); }
  73% { clip-path: inset(70% 0 10% 0); transform: translate( 3px,0); }
  75% { clip-path: inset(100% 0 0 0);  transform: translate(0); }
}

@keyframes glitch-clip-b {
  0%,90%,100% { clip-path: inset(100% 0 0 0); transform: translate(0); }
  6%  { clip-path: inset(60% 0 15% 0); transform: translate( 5px,0) skewX( 3deg); }
  9%  { clip-path: inset(25% 0 55% 0); transform: translate(-4px,0); }
  12% { clip-path: inset(100% 0 0 0);  transform: translate(0); }
  44% { clip-path: inset(75% 0 5%  0); transform: translate(-5px,0) skewX(-4deg); }
  45% { clip-path: inset(100% 0 0 0);  transform: translate(0); }
  74% { clip-path: inset(20% 0 65% 0); transform: translate( 4px,0) skewX( 2deg); }
  76% { clip-path: inset(100% 0 0 0);  transform: translate(0); }
}

/* ── GLITCH BANNER — scatto glitch breve per i banner livello/combo */
@keyframes superGlitch {
  0%   { transform: translate(0) skewX(0); filter: none; }
  8%   { transform: translate(-6px,2px) skewX(-4deg); filter: hue-rotate(90deg)  brightness(1.6); }
  16%  { transform: translate( 6px,-2px) skewX(3deg);  filter: hue-rotate(-45deg) saturate(2); }
  24%  { transform: translate(-4px,0)   skewX(-2deg); filter: brightness(2.2)   saturate(3); }
  32%  { transform: translate(0) skewX(0); filter: none; }
  40%  { transform: translate(3px,1px);  filter: hue-rotate(180deg) brightness(1.3); }
  48%  { transform: translate(-2px,0) skewX(1deg); filter: none; }
  56%  { transform: translate(0) skewX(0); filter: brightness(1.5); }
  64%  { transform: translate(-5px,-1px) skewX(-3deg); filter: hue-rotate(270deg); }
  72%  { transform: translate(4px,0); filter: none; }
  80%,100% { transform: translate(0) skewX(0); filter: none; }
}
.banner-glitch {
  animation: superGlitch 0.55s ease forwards !important;
}

@keyframes flicker {
  0%,18%,22%,25%,53%,57%,100% { opacity: 1; }
  20%,24%,55%                 { opacity: 0.35; }
}

/* ══════════════════════════════════════════════════════════════════
   SCHERMI GENERALI — base condivisa da tutti i .schermo
   ══════════════════════════════════════════════════════════════════ */
.schermo {
  position       : fixed;
  inset          : 0;
  z-index        : 10;
  display        : flex;
  flex-direction : column;
  align-items    : center;
  justify-content: center;
  gap            : 16px;
}

#schermoInizio { display: flex; }
#schermoGioco { display: none; }

/* ══════════════════════════════════════════════════════════════════
   SCHERMO INIZIO — menu principale con titolo, input e pulsante
   ══════════════════════════════════════════════════════════════════ */
.titolo {
  font-family    : 'Planet Kosmos', sans-serif;
  font-weight    : 900;
  font-size      : clamp(58px, 11vw, 108px);
  letter-spacing : 0.15em;
  color          : var(--bianco);
  text-shadow    :
    3px 3px 0 var(--arancio),
    -3px -3px 0 var(--cyan),
    0 0 40px var(--glow-a),
    0 0 80px rgba(255,107,26,0.25);
  animation      : flicker 2.5s infinite;
}
#schermoInizio .titolo {
  color: #fff;
  text-shadow:
    3px 3px 0 var(--menu-accent-b),
    -3px -3px 0 var(--menu-accent-a),
    0 0 40px var(--menu-glow-a),
    0 0 80px var(--menu-glow-b);
  transition: text-shadow 1.8s ease;
}
#schermoInizio .titolo::before {
  color: var(--menu-accent-a);
  transition: color 1.8s ease;
}
#schermoInizio .titolo::after {
  color: var(--menu-accent-b);
  transition: color 1.8s ease;
}
.sottotitolo {
  font-family    : 'Planet Kosmos', sans-serif;
  font-size      : 12px;
  letter-spacing : 0.45em;
  color          : rgba(245,240,232,0.4);
  text-transform : uppercase;
  margin-top     : -12px;
}
#schermoInizio .sottotitolo {
  color: var(--menu-accent-a);
  text-shadow: 0 0 12px var(--menu-glow-a), 0 0 22px var(--menu-glow-b);
  transition: color 1.8s ease, text-shadow 1.8s ease;
}

.campo-nome-wrap {
  display        : flex;
  flex-direction : column;
  align-items    : center;
  gap            : 8px;
  margin-top     : 10px;
}

.campo-nome-label {
  font-family    : 'Planet Kosmos', sans-serif;
  font-size      : 10px;
  letter-spacing : 0.28em;
  text-transform : uppercase;
  color          : rgba(26,184,255,0.7);
}
#schermoInizio .campo-nome-label {
  color: var(--menu-accent-b);
  text-shadow: 0 0 10px var(--menu-glow-b);
  transition: color 1.8s ease, text-shadow 1.8s ease;
}

#inputNomeGiocatore {
  width          : min(320px, 82vw);
  text-transform : uppercase;
  letter-spacing : 0.12em;
  box-shadow     : 0 0 18px rgba(26,184,255,0.08);
  cursor         : text;
}
#schermoInizio #inputNomeGiocatore {
  border-color: var(--menu-accent-a);
  box-shadow: 0 0 18px var(--menu-glow-a);
  transition: border-color 1.8s ease, box-shadow 1.8s ease;
}
#schermoInizio #inputNomeGiocatore::placeholder {
  color: var(--menu-accent-a);
  opacity: .48;
  transition: color 1.8s ease;
}
#schermoInizio #inputNomeGiocatore:focus {
  border-color: var(--menu-accent-b);
  box-shadow: 0 0 20px var(--menu-glow-b);
}

#astroHint {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 2;
  color: rgba(255,255,255,.35);
  font: 9px Arial, sans-serif;
  letter-spacing: .24em;
  text-align: right;
  pointer-events: none;
}

/* ── INPUT / SELECT ────────────────────────────────────────────── */
input, select {
  background   : rgba(0,0,0,0.65);
  border       : 1px solid var(--bordo-a);
  color        : var(--bianco);
  font-family  : 'Share Tech Mono', monospace;
  font-size    : 16px;
  padding      : 12px 20px;
  border-radius: var(--raggio-controllo);
  outline      : none;
  width        : 250px;
  text-align   : center;
  transition   : border-color 0.2s, box-shadow 0.2s;
}
input::placeholder { color: rgba(245,240,232,0.22); }
input:focus,
select:focus {
  border-color : var(--arancio);
  box-shadow   : 0 0 18px var(--glow-a);
}
select option { background: #080400; color: var(--bianco); }

/* ── PULSANTE PRINCIPALE ───────────────────────────────────────── */
.pulsante {
  background     : transparent;
  border         : 2px solid var(--arancio);
  color          : var(--bianco);
  font-family    : 'Planet Kosmos', sans-serif;
  font-weight    : 700;
  font-size      : 15px;
  letter-spacing : 0.22em;
  padding        : 14px 50px;
  border-radius  : var(--raggio-controllo);
  cursor         : pointer;
  position       : relative;
  overflow       : hidden;
  transition     : color 0.2s, box-shadow 0.2s;
  text-shadow    : 1px 1px 0 var(--arancio);
}
.pulsante::before {
  content          : '';
  position         : absolute;
  inset            : 0;
  background       : linear-gradient(135deg, var(--arancio), var(--cyan));
  transform        : scaleX(0);
  transform-origin : left;
  transition       : transform 0.25s ease;
  z-index          : -1;
}
.pulsante:hover {
  color       : #000;
  box-shadow  : 0 0 28px var(--glow-a), 0 0 50px var(--glow-c);
  text-shadow : none;
}
.pulsante:hover::before { transform: scaleX(1); }

#schermoInizio .pulsante {
  border-color: var(--menu-accent-b);
  color: #fff;
  text-shadow: 1px 1px 0 var(--menu-accent-a);
  box-shadow: 0 0 18px var(--menu-glow-b);
  transition:
    color .2s,
    box-shadow 1.8s ease,
    border-color 1.8s ease,
    text-shadow 1.8s ease;
}
#schermoInizio .pulsante::before {
  background: linear-gradient(135deg, var(--menu-accent-a), var(--menu-accent-b));
}
#schermoInizio .pulsante:hover {
  color: #000;
  box-shadow: 0 0 28px var(--menu-glow-a), 0 0 50px var(--menu-glow-b);
  text-shadow: none;
}

#schermoInizio #astroHint {
  color: var(--menu-accent-a);
  text-shadow: 0 0 10px var(--menu-glow-a);
  transition: color 1.8s ease, text-shadow 1.8s ease;
}

/* ══════════════════════════════════════════════════════════════════
   SCHERMO GIOCO — layout orizzontale: hold | canvas | pannello
   ══════════════════════════════════════════════════════════════════ */
#schermoGioco {
  display         : none;
  flex-direction  : row;
  align-items     : flex-start;
  justify-content : center;
  gap             : 20px;
  padding-top     : 14px;
}

#pannelloHold {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 140px;
  padding-top: 2px;
}

.valore-punteggio { font-size: 22px; }
.riquadro-hold { padding: 10px; }
.hint-hold {
  margin-top: 4px;
  color: rgba(26,184,255,.3);
  text-align: center;
  font-size: 9px;
  letter-spacing: .2em;
}
.combo-info { display: none; }
.titolo-classifica { font-size: clamp(32px,6vw,60px); }
.pulsante-abbandona { border-color: rgba(26,184,255,.5); margin-top: 4px; }
.pulsante-salva-card { border-color: rgba(255,157,77,.4); color: rgba(255,157,77,.8); }

#controlliTouch { display: none; }

/* ── CANVAS TETRIS ─────────────────────────────────────────────── */
#gioco {
  background : rgba(2, 6, 18, 0.48);
  border     : 1.5px solid rgba(138, 195, 255, 0.55);
  box-shadow :
    0 0 26px rgba(68, 135, 255, 0.16),
    0 0 72px rgba(88, 81, 216, 0.10),
    inset 0 0 40px rgba(0,0,0,0.62);
  display    : block;
  border-radius: var(--raggio-controllo);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* ── ZOOM DROP — animazione scala su hard drop e combo ──────────── */
#layoutGioco {
  display          : flex;
  flex-direction   : row;
  align-items      : flex-start;
  gap              : 20px;
  padding-top      : 12px;
  transition       : transform 0.08s cubic-bezier(0.25,0.46,0.45,0.94);
  transform-origin : center center;
}
#layoutGioco.zoom-drop {
  animation: zoomDrop 0.22s cubic-bezier(0.25,0.46,0.45,0.94) forwards;
}
@keyframes zoomDrop {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.045); }
  70%  { transform: scale(0.985); }
  100% { transform: scale(1); }
}

/* ── PANNELLI LATERALI ─────────────────────────────────────────── */
.pannello-laterale {
  display        : flex;
  flex-direction : column;
  gap            : 14px;
  width          : 160px;
  padding-top    : 2px;
}

/* ── RIQUADRO — card con etichetta floating e angolino decorativo ── */
.riquadro {
  background     : rgba(4, 9, 24, 0.55);
  border         : 1px solid rgba(124, 174, 255, 0.28);
  border-radius  : var(--raggio-card);
  padding        : 13px 15px;
  position       : relative;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
/* Angolino decorativo in basso a destra */
.riquadro::after {
  content       : '';
  position      : absolute;
  bottom        : 3px;
  right         : 4px;
  width         : 7px;
  height        : 7px;
  border-bottom : 1px solid var(--bordo-c);
  border-right  : 1px solid var(--bordo-c);
  border-radius : 0 0 3px 0;
}
/* Etichetta floating sul bordo superiore */
.riquadro::before {
  content        : attr(data-etichetta);
  position       : absolute;
  top            : -9px;
  left           : 10px;
  font-size      : 9px;
  letter-spacing : 0.3em;
  color          : rgba(26,184,255,0.55);
  padding        : 0 6px;
  text-transform : uppercase;
  background     : transparent;
}

/* ── VALORI NUMERICI ───────────────────────────────────────────── */
.valore {
  font-family  : 'Planet Kosmos', sans-serif;
  font-size    : 30px;
  font-weight  : 700;
  color        : var(--bianco);
  text-shadow  : 1px 1px 0 var(--arancio), 0 0 14px var(--glow-a);
}
.valore.nome {
  font-size   : 15px;
  color       : var(--bianco);
  text-shadow : none;
  word-break  : break-word;
}

/* ── BARRA PROGRESSO LIVELLO ───────────────────────────────────── */
.barra-sfondo {
  margin-top    : 8px;
  height        : 3px;
  background    : rgba(255,255,255,0.07);
  border-radius : var(--raggio-pill);
  overflow      : hidden;
}
.barra-riempimento {
  height        : 100%;
  background    : linear-gradient(90deg, var(--arancio), var(--cyan));
  border-radius : var(--raggio-pill);
  transition    : width 0.5s ease;
  width         : 0%;
  box-shadow    : 0 0 8px var(--glow-a);
}

/* ── TAG MODALITÀ ──────────────────────────────────────────────── */

/* ── TESTI CONTROLLI ───────────────────────────────────────────── */
.controlli {
  font-size   : 11px;
  color       : rgba(245,240,232,0.32);
  line-height : 2.0;
}
.controlli span { color: var(--arancio); }

/* ── CANVAS ANTEPRIMA / HOLD ───────────────────────────────────── */
#canvasNext, #canvasHold { display: block; margin: 6px auto 0; }

.info-piccolo {
  font-size      : 11px;
  color          : rgba(245,240,232,0.28);
  margin-top     : 4px;
  letter-spacing : 0.05em;
}
.info-piccolo span { color: var(--arancio); }

/* ── LOCK BAR — barra che si riempie prima del blocco pezzo ─────── */
#lockBar {
  height        : 3px;
  background    : rgba(255,255,255,0.07);
  border-radius : var(--raggio-pill);
  overflow      : hidden;
  margin-top    : 6px;
}
#lockFill {
  height        : 100%;
  background    : linear-gradient(90deg, var(--arancio), var(--cyan));
  border-radius : var(--raggio-pill);
  width         : 0%;
}


/* ── MODALITÀ HARDCORE — rimappa i colori UI su cyan ───────────── */

/* ══════════════════════════════════════════════════════════════════
   SCHERMO PAUSA
   ══════════════════════════════════════════════════════════════════ */
#schermoPausa {
  display         : none;
  flex-direction  : column;
  align-items     : center;
  justify-content : center;
  gap             : 22px;
  background      : rgba(0,0,0,0.70);
  backdrop-filter : blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index         : 12;
}
.pausa-titolo {
  font-family    : 'Planet Kosmos', sans-serif;
  font-weight    : 900;
  font-size      : clamp(36px,7vw,64px);
  letter-spacing : 0.22em;
  color          : var(--bianco);
  text-shadow    : 2px 2px 0 var(--arancio), -2px -2px 0 var(--cyan), 0 0 40px var(--glow-a);
  animation      : flicker 2s infinite;
}

/* ══════════════════════════════════════════════════════════════════
   SCHERMO COUNTDOWN — 3, 2, 1 prima dell'inizio partita
   ══════════════════════════════════════════════════════════════════ */
#schermoCountdown {
  display         : none;
  flex-direction  : column;
  align-items     : center;
  justify-content : center;
  z-index         : 13;
  background      : rgba(0,0,0,0.72);
}
.cd-numero {
  font-family  : 'Planet Kosmos', sans-serif;
  font-weight  : 900;
  font-size    : clamp(90px,20vw,180px);
  color        : var(--bianco);
  text-shadow  : 4px 4px 0 var(--arancio), -4px -4px 0 var(--cyan), 0 0 60px var(--glow-a);
  animation    : cdPop 0.9s ease-out forwards;
}
@keyframes cdPop {
  0%      { transform: scale(2.2) rotate(-5deg); opacity: 0; }
  35%,75% { transform: scale(1)   rotate(0deg);  opacity: 1; }
  100%    { transform: scale(0.4) rotate(5deg);  opacity: 0; }
}

/* ══════════════════════════════════════════════════════════════════
   SCHERMO GAME OVER / CLASSIFICA
   ══════════════════════════════════════════════════════════════════ */
#schermoClassifica {
  display         : none;
  flex-direction  : column;
  align-items     : center;
  justify-content : center;
  gap             : 16px;
  background      : rgba(0,0,0,0.76);
  backdrop-filter : blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index         : 15;
  overflow-y      : auto;
  padding         : 22px 0;
}
.punteggio-finale {
  font-family    : 'Planet Kosmos', sans-serif;
  font-size      : 20px;
  color          : rgba(245,240,232,0.38);
  letter-spacing : 0.12em;
  text-align     : center;
}
.punteggio-finale span {
  display     : block;
  font-size   : 50px;
  color       : var(--bianco);
  text-shadow : 2px 2px 0 var(--arancio), 0 0 30px var(--glow-a);
  margin-top  : 6px;
}

/* ── CLASSIFICA ────────────────────────────────────────────────── */
.classifica-box {
  background    : rgba(0,0,0,0.74);
  border        : 1px solid var(--bordo-a);
  border-radius : var(--raggio-card);
  padding       : 20px 26px;
  width         : min(420px, 92vw);
}
.classifica-titolo {
  font-family    : 'Planet Kosmos', sans-serif;
  font-size      : 12px;
  letter-spacing : 0.4em;
  color          : rgba(26,184,255,0.55);
  text-transform : uppercase;
  margin-bottom  : 14px;
  text-align     : center;
}
.classifica-riga {
  display       : flex;
  align-items   : center;
  gap           : 10px;
  padding       : 7px 0;
  border-bottom : 1px solid rgba(255,255,255,0.05);
  font-size     : 14px;
}
.classifica-riga:last-child { border-bottom: none; }

.cl-pos       { font-family:'Planet Kosmos',sans-serif; font-size:11px; color:rgba(255,255,255,.28); width:24px; text-align:right; flex-shrink:0; }
.cl-pos.oro   { color: #ffcc00; }
.cl-pos.arg   { color: #c0c0cc; }
.cl-pos.bron  { color: #cd7f32; }
.cl-nome      { flex:1; color:var(--bianco); letter-spacing:.05em; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cl-punt      { font-family:'Planet Kosmos',sans-serif; font-size:15px; color:var(--bianco); text-shadow:1px 1px 0 var(--arancio); }
.cl-new       { font-size:9px; letter-spacing:.2em; color:var(--arancio); background:rgba(255,107,26,0.1); border:1px solid var(--bordo-a); border-radius:var(--raggio-controllo); padding:1px 8px; flex-shrink:0; }
.cl-vuoto     { color:rgba(255,255,255,.2); font-size:13px; text-align:center; padding:12px 0; }

/* ── PULSANTI GAME OVER ────────────────────────────────────────── */
.pulsanti-go {
  display     : flex;
  gap         : 12px;
  flex-wrap   : wrap;
  justify-content: center;
}
.pulsante-small {
  background     : transparent;
  border         : 1px solid var(--bordo-a);
  color          : rgba(245,240,232,0.7);
  font-family    : 'Planet Kosmos', sans-serif;
  font-size      : 12px;
  letter-spacing : 0.15em;
  padding        : 9px 20px;
  border-radius  : var(--raggio-controllo);
  cursor         : pointer;
  transition     : all 0.2s;
}
.pulsante-small:hover {
  background : rgba(255,107,26,0.1);
  color      : var(--bianco);
  box-shadow : 0 0 14px var(--glow-a);
}
.pulsante-small:disabled { opacity: .45; cursor: wait; }
.pulsante-condividi { border-color: var(--bordo-c); }
.pulsante-condividi:hover {
  background : rgba(26,184,255,0.1);
  box-shadow : 0 0 14px var(--glow-c);
}

/* ══════════════════════════════════════════════════════════════════
   BANNER LIVELLO / COMBO — elementi fissi a schermo durante il gioco
   ══════════════════════════════════════════════════════════════════ */
#bannerLivello {
  position    : fixed;
  top         : 50%;
  left        : 50%;
  transform   : translate(-50%,-50%) scale(0);
  z-index     : 9999;
  font-family : 'Planet Kosmos', sans-serif;
  font-weight : 900;
  font-size   : clamp(30px,7vw,62px);
  letter-spacing : 0.2em;
  text-align  : center;
  pointer-events : none;
  transition  : transform 0.3s cubic-bezier(.34,1.56,.64,1), opacity 0.3s ease;
  opacity     : 0;
}
#bannerLivello.mostra  { transform: translate(-50%,-50%) scale(1);   opacity: 1; }
#bannerLivello.nascondi{ transform: translate(-50%,-50%) scale(1.5); opacity: 0; }

#bannerCombo {
  position    : fixed;
  top         : 38%;
  left        : 50%;
  transform   : translate(-50%,-50%) scale(0);
  z-index     : 99999;
  font-family : 'Planet Kosmos', sans-serif;
  font-weight : 900;
  font-size   : clamp(22px,5vw,44px);
  letter-spacing : 0.15em;
  text-align  : center;
  pointer-events : none;
  white-space : nowrap;
  transition  : transform 0.25s cubic-bezier(.34,1.56,.64,1), opacity 0.25s ease;
  opacity     : 0;
}
#bannerCombo.mostra  { transform: translate(-50%,-50%) scale(1);   opacity: 1; }
#bannerCombo.nascondi{ transform: translate(-50%,-50%) scale(1.5); opacity: 0; }

/* ══════════════════════════════════════════════════════════════════
   IMPOSTAZIONI — pulsante ingranaggio e pannello overlay
   ══════════════════════════════════════════════════════════════════ */
#btnImpostazioni {
  position       : fixed;
  bottom         : max(16px, env(safe-area-inset-bottom));
  left           : max(16px, env(safe-area-inset-left));
  z-index        : 50;
  width          : 48px;
  height         : 48px;
  border-radius  : 50%;
  background     : rgba(0,0,0,0.78);
  border         : 1.5px solid var(--bordo-a);
  color          : rgba(245,240,232,0.7);
  font-size      : 22px;
  cursor         : pointer;
  display        : flex;
  align-items    : center;
  justify-content: center;
  transition     : border-color 0.2s, color 0.2s, box-shadow 0.2s, transform 0.4s;
  backdrop-filter: blur(6px);
}
#btnImpostazioni:hover {
  border-color : var(--arancio);
  color        : var(--arancio);
  box-shadow   : 0 0 20px var(--glow-a);
}
#btnImpostazioni.aperto { transform: rotate(90deg); }

#schermoImpostazioni {
  position        : fixed;
  inset           : 0;
  z-index         : 40;
  display         : none;
  align-items     : center;
  justify-content : center;
  background      : rgba(0,0,0,0.72);
  backdrop-filter : blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#pannelloImpostazioni {
  background    : rgba(0,0,0,0.86);
  border        : 1px solid var(--bordo-a);
  border-radius : var(--raggio-card);
  padding       : 32px 34px;
  width         : min(500px, 94vw);
  max-height    : 90vh;
  max-height    : 90dvh;
  overflow-y    : auto;
  position      : relative;
  font-family   : "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.imp-titolo {
  font-family    : 'Planet Kosmos', sans-serif;
  font-weight    : 900;
  font-size      : 20px;
  letter-spacing : 0.3em;
  color          : var(--bianco);
  text-shadow    : 1px 1px 0 var(--arancio), -1px -1px 0 var(--cyan);
  margin-bottom  : 26px;
  text-align     : center;
}
.imp-sezione {
  font-family    : 'Planet Kosmos', sans-serif;
  font-size      : 9px;
  letter-spacing : 0.4em;
  color          : rgba(26,184,255,0.42);
  text-transform : uppercase;
  margin         : 22px 0 12px;
  padding-bottom : 6px;
  border-bottom  : 1px solid rgba(255,107,26,0.12);
}
.imp-riga {
  display       : flex;
  align-items   : center;
  gap           : 12px;
  padding       : 9px 0;
  border-bottom : 1px solid rgba(255,255,255,0.04);
}
.imp-riga:last-child { border-bottom: none; }
.imp-icona  { font-size: 17px; width: 24px; text-align: center; flex-shrink: 0; }
.imp-label  { flex:1; font-size:13px; color:rgba(245,240,232,0.58); letter-spacing:0.05em; }
.imp-valore { font-family:"Helvetica Neue", Helvetica, Arial, sans-serif; font-size:12px; color:var(--arancio); min-width:36px; text-align:right; flex-shrink:0; }
.imp-select {
  flex: 1;
  min-width: 0;
  width: auto;
  padding: 8px 10px;
  border-color: var(--bordo-c);
  border-radius: var(--raggio-controllo);
  color: var(--bianco);
  font: 12px 'Share Tech Mono', monospace;
}
.imp-select:focus { border-color: var(--cyan); box-shadow: 0 0 12px var(--glow-c); }
.imp-rigenera {
  width: 100%;
  margin-top: 12px;
  padding: 10px 14px;
  border: 1px solid var(--bordo-c);
  border-radius: var(--raggio-controllo);
  background: rgba(26,184,255,.08);
  color: var(--bianco);
  font: 11px 'Share Tech Mono', monospace;
  letter-spacing: .18em;
  cursor: pointer;
  transition: background .2s, border-color .2s, box-shadow .2s;
}
.imp-rigenera:hover {
  background: rgba(26,184,255,.16);
  border-color: var(--cyan);
  box-shadow: 0 0 16px var(--glow-c);
}

/* ── SLIDER ────────────────────────────────────────────────────── */
.imp-slider {
  -webkit-appearance : none;
  appearance         : none;
  flex               : 1;
  height             : 2px;
  border-radius      : var(--raggio-pill);
  background         : rgba(255,255,255,0.1);
  outline            : none;
  cursor             : pointer;
  min-width          : 80px;
}
.imp-slider::-webkit-slider-thumb {
  -webkit-appearance : none;
  width              : 14px;
  height             : 14px;
  border-radius      : 50%;
  background         : var(--arancio);
  box-shadow         : 0 0 8px var(--glow-a);
  cursor             : pointer;
}
.imp-slider::-moz-range-thumb {
  width         : 14px;
  height        : 14px;
  border-radius : 50%;
  background    : var(--arancio);
  border        : none;
  box-shadow    : 0 0 8px var(--glow-a);
}

/* ── TOGGLE ────────────────────────────────────────────────────── */
.imp-toggle {
  position  : relative;
  width     : 42px;
  height    : 23px;
  flex-shrink: 0;
}
.imp-toggle input {
  opacity  : 0;
  width    : 0;
  height   : 0;
  position : absolute;
}
.imp-toggle-track {
  position      : absolute;
  inset         : 0;
  border-radius : 12px;
  background    : rgba(255,255,255,0.08);
  border        : 1px solid rgba(255,255,255,0.14);
  cursor        : pointer;
  transition    : background 0.2s, border-color 0.2s;
}
.imp-toggle input:checked + .imp-toggle-track {
  background   : rgba(255,107,26,0.28);
  border-color : var(--bordo-a);
}
.imp-toggle-track::after {
  content       : '';
  position      : absolute;
  top           : 3px;
  left          : 3px;
  width         : 15px;
  height        : 15px;
  border-radius : 50%;
  background    : rgba(255,255,255,0.35);
  transition    : transform 0.2s, background 0.2s;
}
.imp-toggle input:checked + .imp-toggle-track::after {
  transform  : translateX(19px);
  background : var(--arancio);
  box-shadow : 0 0 8px var(--glow-a);
}

/* ── PULSANTE CHIUDI IMPOSTAZIONI ──────────────────────────────── */
#chiudiImpostazioni {
  position   : absolute;
  top        : 14px;
  right      : 16px;
  background : transparent;
  border     : none;
  color      : rgba(255,255,255,0.3);
  font-size  : 22px;
  cursor     : pointer;
  line-height: 1;
  transition : color 0.2s;
  padding    : 4px;
}
#chiudiImpostazioni:hover { color: white; }

/* ── CANVAS CARD — nascosto, usato solo da salvaCard() ──────────── */
#canvasCard { display: none; }

@media (max-width: 860px), (pointer: coarse) {
  #astroHint { display: none; }
  .riquadro { backdrop-filter: none; -webkit-backdrop-filter: none; }
  #gioco { backdrop-filter: none; -webkit-backdrop-filter: none; }

  #schermoInizio .titolo {
    font-size: clamp(38px, 11vw, 64px);
    letter-spacing: .08em;
  }

  #schermoInizio .sottotitolo {
    font-size: 10px;
    letter-spacing: .2em;
    text-align: center;
  }

  #schermoGioco {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    align-items: center;
    justify-content: flex-start;
    padding: max(8px, env(safe-area-inset-top)) 12px max(76px, calc(env(safe-area-inset-bottom) + 72px));
  }

  #layoutGioco {
    width: 100%;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 0;
  }

  #pannelloHold {
    order: 1;
    width: min(100%, 420px);
    flex-direction: row;
    justify-content: center;
    align-items: stretch;
    gap: 6px;
    padding: 0;
  }

  #pannelloHold .riquadro {
    min-width: 0;
    flex: 1 1 0;
    padding: 7px 5px;
  }

  #pannelloHold .valore { font-size: 18px; }
  #pannelloHold .valore-punteggio { font-size: 18px; }
  #canvasHold { max-width: 100%; height: auto; }

  #gioco { border-radius: 12px; }

  #gioco {
    order: 2;
    width: min(76vw, 28vh, 320px);
    width: min(76vw, 28dvh, 320px);
    height: auto;
    max-width: 100%;
    aspect-ratio: 1 / 2;
  }

  .pannello-laterale {
    order: 4;
    width: min(100%, 420px);
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    padding: 0;
  }

  .pannello-laterale > .riquadro {
    min-width: 0;
    flex: 1 1 100px;
    padding: 8px;
  }

  .pannello-laterale > .riquadro[data-etichetta="Controlli"] { display: none; }

  #controlliTouch {
    order: 3;
    width: min(100%, 420px);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 2px 0 max(8px, env(safe-area-inset-bottom));
  }

  .tasto-touch {
    min-height: 48px;
    border: 1px solid var(--bordo-c);
    border-radius: var(--raggio-controllo);
    background: rgba(0,0,0,.78);
    color: var(--bianco);
    font: 400 12px 'Planet Kosmos', 'Share Tech Mono', monospace;
    letter-spacing: .04em;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
  }

  .tasto-direzione { color: var(--cyan); font-size: 20px; }
  .tasto-drop { border-color: var(--bordo-a); color: var(--arancio); }
  .tasto-touch:active { background: rgba(26,184,255,.22); }
  .tasto-touch:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
}

@media (orientation: landscape) and (max-width: 860px),
       (orientation: landscape) and (pointer: coarse) {
  #schermoGioco {
    align-items: flex-start;
    padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-bottom));
  }

  #layoutGioco {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
  }

  #pannelloHold {
    width: min(22vw, 220px);
    flex-direction: column;
  }

  #gioco {
    width: auto;
    height: min(76vh, 620px);
    height: min(76dvh, 620px);
    max-width: none;
  }

  .pannello-laterale {
    width: min(22vw, 220px);
    flex-direction: column;
  }

  #controlliTouch {
    flex-basis: 100%;
    width: min(100%, 560px);
    margin: 0 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }

  #flickerOverlay { display: none !important; }
}
