:root {
  --bg: #0b0418;
  --pur: #a64dff;
  --pk: #ff2e97;
  --or: #ff8a1f;
  --tx: #f3e8ff;
  --dim: #8f7bb3;
  --pn: rgba(22, 8, 44, 0.85);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--tx);
  font: 16px 'Share Tech Mono', ui-monospace, monospace;
  overflow-x: hidden;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
  -webkit-tap-highlight-color: transparent;
}

/* SCENOGRAFIA SFONDO CYBERPUNK */
.sky {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: linear-gradient(#1a0536 0%, #3a0b5c 45%, #7a1b6e 62%, #ff5a4d 78%, #0b0418 78.1%);
}

.sun {
  position: absolute;
  left: 50%;
  top: 34%;
  width: min(46vw, 320px);
  aspect-ratio: 1;
  translate: -50% 0;
  border-radius: 50%;
  background: linear-gradient(#ffd23f, #ff8a1f 45%, #ff2e97);
  box-shadow: 0 0 80px rgba(255, 90, 77, 0.6);
  overflow: hidden;
}

.sun::after {
  content: "";
  position: absolute;
  inset: 48% 0 0;
  background: repeating-linear-gradient(transparent 0 6px, #7a1b6e 6px 10px);
}

.grid {
  position: absolute;
  left: -60%;
  right: -60%;
  bottom: 0;
  height: 24vh;
  background: repeating-linear-gradient(90deg, var(--pur) 0 2px, transparent 2px 70px),
              repeating-linear-gradient(0deg, var(--pur) 0 2px, transparent 2px 50px),
              var(--bg);
  transform: perspective(260px) rotateX(58deg);
  transform-origin: top;
  animation: flow 1.6s linear infinite;
  box-shadow: 0 0 40px var(--pur) inset;
}

@keyframes flow {
  to { background-position: 0 0, 0 50px, 0 0; }
}

.scan {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: repeating-linear-gradient(transparent 0 2px, rgba(0, 0, 0, 0.18) 2px 3px);
  mix-blend-mode: multiply;
}

/* LAYOUT PRINCIPALE */
main {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding: 18px 16px;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-height: calc(100vh - 36px);
}

.screen.on {
  display: flex;
  animation: in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); filter: blur(4px); }
}

h1, h2, h3, .btn, .big2, .rank {
  font-family: Orbitron, 'Arial Black', sans-serif;
}

/* LOGO CYBERPUNK CON GLITCH EFFECT */
.logo {
  position: relative;
  font-size: clamp(54px, 17vw, 92px);
  font-weight: 800;
  letter-spacing: 0.12em;
  margin-top: 6px;
  background: linear-gradient(var(--tx) 30%, var(--pk) 60%, var(--or));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 46, 151, 0.7));
}

.logo::before, .logo::after {
  content: attr(data-t);
  position: absolute;
  inset: 0;
  background: inherit;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: glitch 4.5s infinite steps(1);
}

.logo::before { translate: -3px 0; filter: hue-rotate(90deg); }
.logo::after { translate: 3px 0; filter: hue-rotate(-60deg); }

@keyframes glitch {
  0%, 90%, 100% { clip-path: inset(0 0 100% 0); }
  91% { clip-path: inset(20% 0 55% 0); }
  93% { clip-path: inset(60% 0 10% 0); }
  95% { clip-path: inset(35% 0 40% 0); }
}

.sub {
  color: var(--or);
  letter-spacing: 0.3em;
  margin-top: -10px;
}

/* STATS BAR */
.stats {
  display: flex;
  gap: 10px;
  width: 100%;
}

.stats div {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  background: var(--pn);
  border: 1px solid rgba(166, 77, 255, 0.5);
  backdrop-filter: blur(8px);
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
}

.stats b {
  display: block;
  font: 800 24px Orbitron, sans-serif;
  color: var(--or);
  text-shadow: 0 0 12px var(--or);
}

small {
  color: var(--dim);
  letter-spacing: 0.18em;
}

/* CARD GIOCHI */
#cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--pn);
  border: 1px solid var(--pur);
  clip-path: polygon(0 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 16px 100%, 0 calc(100% - 16px));
  backdrop-filter: blur(8px);
  animation: in 0.6s both;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card.done {
  border-color: var(--or);
}

.ic {
  font-size: 34px;
  color: var(--pk);
  text-shadow: 0 0 14px var(--pk);
  width: 44px;
  text-align: center;
}

.ct { flex: 1; }
.ct h3 { letter-spacing: 0.2em; }
.ct p { color: var(--dim); font-size: 14px; }

.ca {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* PULSANTI */
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  border: 0;
  padding: 12px 20px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #1a0536;
  background: linear-gradient(90deg, var(--or), var(--pk));
  clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
  transition: transform 0.12s, filter 0.12s;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.2) drop-shadow(0 0 12px var(--pk));
}

.btn:active {
  transform: scale(0.95);
}

.btn:disabled {
  background: rgba(255, 138, 31, 0.18);
  color: var(--or);
  cursor: default;
}

.ghost {
  background: none;
  border: 1px solid rgba(166, 77, 255, 0.6);
  padding: 7px 12px;
  color: var(--tx);
  font-size: 13px;
  letter-spacing: 0.1em;
  transition: 0.15s;
}

.ghost:hover {
  border-color: var(--pk);
  box-shadow: 0 0 12px var(--pk);
}

button:focus-visible {
  outline: 2px solid var(--or);
  outline-offset: 2px;
}

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-top: auto;
  color: var(--dim);
  font-size: 13px;
  gap: 8px;
}

.foot b { color: var(--tx); }

#mute {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: 10px;
  z-index: 60;
  background: var(--pn);
}

#mute.off {
  opacity: 0.45;
  text-decoration: line-through;
}

/* ARENA E GAMEPLAY (FIX CORRETTO HUD & POSIZIONAMENTI) */
#game header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  font: 800 14px Orbitron, sans-serif;
  letter-spacing: 0.2em;
  gap: 8px;
  padding-right: 46px;
}

#arena {
  position: relative;
  width: 100%;
  height: min(62vh, 480px);
  background: rgba(10, 3, 24, 0.88);
  border: 1px solid var(--pur);
  box-shadow: 0 0 35px rgba(166, 77, 255, 0.35) inset, 0 0 25px rgba(166, 77, 255, 0.25);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  cursor: crosshair;
}

.intro {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  padding: 20px;
  animation: in 0.4s;
}

.intro h2 {
  font-size: 34px;
  letter-spacing: 0.2em;
  color: var(--or);
  text-shadow: 0 0 18px var(--or);
}

.intro p {
  max-width: 30ch;
  color: var(--dim);
}

.big {
  width: 180px;
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 800 30px Orbitron, sans-serif;
  color: #1a0536;
  background: radial-gradient(circle at 35% 30%, #ffd23f, var(--or) 50%, var(--pk));
  box-shadow: 0 0 50px var(--pk);
  pointer-events: none;
}

.pop { animation: pop 0.16s; }
@keyframes pop { 50% { transform: scale(0.88); filter: brightness(1.4); } }

/* BARRA DI PROGRESSO E CONTATORE IN ARENA */
#arena .bar {
  position: absolute;
  right: 14px;
  top: 52px;
  bottom: 20px;
  width: 8px;
  height: auto;
  background: rgba(166, 77, 255, 0.2);
  border-radius: 4px;
  overflow: hidden;
}

#arena .bar i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(0deg, var(--or), var(--pk));
}

#arena .cnt {
  position: absolute;
  top: 14px;
  right: 14px;
  font: 800 22px Orbitron, sans-serif;
  color: var(--tx);
  text-shadow: 0 0 12px var(--pur);
  pointer-events: none;
}

.cnt.res {
  position: relative;
  top: auto;
  right: auto;
  font-size: 28px;
  color: var(--or);
}

/* SFIDA: SIGNAL */
.sig {
  width: 86%;
  height: 55%;
  display: grid;
  place-items: center;
  font: 800 28px Orbitron, sans-serif;
  letter-spacing: 0.2em;
  border: 2px solid var(--pur);
  pointer-events: none;
  transition: 0.08s;
}

.sig.go {
  background: var(--or);
  color: #1a0536;
  border-color: #fff;
  box-shadow: 0 0 60px var(--or);
}

.sig.fake {
  background: var(--pur);
  color: #fff;
  border-color: #fff;
  box-shadow: 0 0 50px var(--pur);
}

/* SFIDA: GRID */
.tgt {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: -29px;
  border-radius: 50%;
  border: 3px solid var(--pk);
  background: radial-gradient(var(--pk) 0 25%, transparent 27%);
  box-shadow: 0 0 22px var(--pk);
  animation: born 0.15s;
}

@keyframes born { from { transform: scale(0.2); opacity: 0; } }

/* SFIDA: TRACE */
.tr {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  border: 3px solid var(--or);
  box-shadow: 0 0 24px var(--or), 0 0 24px var(--or) inset;
  pointer-events: none;
  transition: background 0.1s, border-color 0.1s;
}

.tr.lock {
  border-color: var(--pk);
  background: rgba(255, 46, 151, 0.3);
  box-shadow: 0 0 34px var(--pk), 0 0 24px var(--pk) inset;
}

.tr.wait { animation: wp 1s infinite alternate; }
@keyframes wp { to { box-shadow: 0 0 56px var(--pk), 0 0 26px var(--pk) inset; } }
.tr.me { border-color: var(--pk); box-shadow: 0 0 24px var(--pk), 0 0 24px var(--pk) inset; }

.pt {
  position: absolute;
  left: -7px;
  top: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px #fff, 0 0 22px var(--pk);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.msg {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% + 62px);
  text-align: center;
  color: var(--or);
  font: 800 14px Orbitron, sans-serif;
  letter-spacing: 0.2em;
  pointer-events: none;
  animation: blink 0.7s infinite alternate;
}

/* SFIDA: SYNC */
.core, .rg {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 60px;
  aspect-ratio: 1;
  border-radius: 50%;
  translate: -50% -50%;
}

.core { border: 3px solid var(--or); box-shadow: 0 0 22px var(--or); }
.rg { border: 3px solid var(--pk); box-shadow: 0 0 22px var(--pk); transform: translate(-50%, -50%) scale(4); translate: 0 0; }

.dots { display: flex; gap: 18px; }
.dots i {
  width: 48px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid var(--pur);
  display: grid;
  place-items: center;
  font: 800 22px Orbitron, sans-serif;
  font-style: normal;
  transition: 0.08s;
}
.dots i.on { background: var(--pk); border-color: #fff; box-shadow: 0 0 30px var(--pk); }
.dots i.q { border-color: var(--or); color: var(--or); box-shadow: 0 0 18px var(--or); }

.track {
  position: relative;
  width: 88%;
  height: 3px;
  margin-top: 40px;
  background: linear-gradient(90deg, transparent, var(--pur) 8%, var(--pur) 92%, transparent);
}

.nd {
  position: absolute;
  top: 50%;
  width: 48px;
  aspect-ratio: 1;
  margin: -24px;
  border-radius: 50%;
  border: 3px dashed var(--or);
  box-shadow: 0 0 20px var(--or), 0 0 14px var(--or) inset;
  animation: spin 3s linear infinite;
}

.mk {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px;
  border-radius: 50%;
  background: var(--pk);
  box-shadow: 0 0 18px var(--pk), 0 0 34px var(--pk);
}

@keyframes spin { to { rotate: 360deg; } }
@keyframes blink { to { opacity: 0.3; } }

.cd {
  font: 800 130px Orbitron, sans-serif;
  color: var(--or);
  text-shadow: 0 0 40px var(--or);
  animation: cd 1s infinite;
}

@keyframes cd {
  from { transform: scale(2); opacity: 0; }
  25% { opacity: 1; }
  to { transform: scale(0.8); opacity: 0.6; }
}

/* SCHERMATA RISULTATI */
#result small { margin-top: 20px; letter-spacing: 0.3em; }

.big2 {
  font-size: clamp(60px, 20vw, 100px);
  font-weight: 800;
  color: var(--or);
  text-shadow: 0 0 30px var(--or);
  animation: in 0.8s;
}

.rank {
  color: var(--pk);
  letter-spacing: 0.2em;
  text-align: center;
  text-shadow: 0 0 14px var(--pk);
}

.rows {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0 18px;
}

.row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 2px 10px;
  align-items: center;
  padding: 10px;
  background: var(--pn);
  border-left: 3px solid var(--pk);
}

.row .bar { width: 100%; height: 8px; position: static; }
.row i { animation: grow 1s cubic-bezier(0.2, 0.8, 0.2, 1); }
.row em { grid-column: 1/3; color: var(--dim); font-style: normal; font-size: 13px; }
.row b.w { color: var(--or); }

@keyframes grow { from { width: 0; } }

/* EFFETTI VISIVI E POPUP METRICHE */
.vd {
  position: absolute;
  top: 11%;
  left: 0;
  right: 0;
  text-align: center;
  font: 800 clamp(24px, 7.5vw, 40px) Orbitron, sans-serif;
  letter-spacing: 0.14em;
  text-shadow: 0 0 18px var(--pur);
  pointer-events: none;
  z-index: 5;
  animation: vd 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.vd.l1 { color: var(--or); text-shadow: 0 0 24px var(--or); }
.vd.l2 {
  font-size: clamp(34px, 11vw, 60px);
  background: linear-gradient(90deg, #ffd23f, #ff2e97, #a64dff, #ffd23f);
  background-size: 200%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px var(--pk));
  animation: vd 0.5s cubic-bezier(0.2, 1.6, 0.4, 1), rb 1s linear infinite;
}

@keyframes vd { from { transform: scale(0.3); opacity: 0; } }
@keyframes rb { to { background-position: 200%; } }

.pa {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 8px;
  height: 8px;
  pointer-events: none;
  animation: pa 1.1s ease-out forwards;
}

@keyframes pa { to { transform: translate(var(--x), var(--y)) scale(0.2); opacity: 0; } }

.fl {
  position: absolute;
  inset: 0;
  background: #fff;
  pointer-events: none;
  z-index: 6;
  animation: fl 0.5s forwards;
}

@keyframes fl { from { opacity: 0.75; } to { opacity: 0; } }

.shake { animation: shake 0.5s; }
@keyframes shake {
  20% { transform: translate(-7px, 3px); }
  40% { transform: translate(7px, -4px); }
  60% { transform: translate(-5px, -3px); }
  80% { transform: translate(4px, 3px); }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  translate: -50% 30px;
  opacity: 0;
  padding: 10px 18px;
  background: var(--pur);
  color: #fff;
  z-index: 70;
  transition: 0.3s;
  pointer-events: none;
  border-radius: 4px;
  font-weight: bold;
}

#toast.show { opacity: 1; translate: -50% 0; }

/* MODALITÀ BLACK ICE */
.iceb {
  width: 100%;
  padding: 10px;
  font: 800 13px Orbitron, sans-serif;
  letter-spacing: 0.25em;
  background: var(--pn);
}

html.ice .iceb { border-color: var(--pk); color: var(--pk); box-shadow: 0 0 18px var(--pk); }
.icep { color: var(--dim); font-size: 12px; margin-top: -10px; text-align: center; }
html.ice .sky, html.ice main { filter: hue-rotate(-70deg) saturate(1.25); }

/* MEDIA QUERIES E ACCESSIBILITÀ */
@media (max-width: 420px) {
  .ca .btn { padding: 10px 12px; }
  .big { width: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01s !important; }
}
