/* Laser Eyes: stile UI del gioco */

:root {
  --cyan: #35e0ff;
  --magenta: #ff4fd8;
  --yellow: #ffd93b;
  --bg-deep: #060a1a;
  --panel: rgba(10, 16, 38, 0.88);
  --text: #eaf6ff;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* niente scroll o zoom di sistema durante il gioco */
  overscroll-behavior: none;
}

.hidden { display: none !important; }

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* La webcam vera resta fuori schermo: serve solo a MediaPipe */
#webcam {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 2px;
  height: 2px;
  opacity: 0;
  pointer-events: none;
}

/* Anteprima webcam in basso a sinistra */
#cam-pip {
  position: fixed;
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: 180px;
  border: 2px solid rgba(53, 224, 255, 0.5);
  border-radius: 10px;
  overflow: hidden;
  z-index: 30;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  background: #000;
}
#cam-pip canvas { display: block; width: 100%; }

/* Schermate a tutto schermo */
.screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background:
    radial-gradient(1200px 700px at 50% 20%, rgba(40, 70, 160, 0.35), transparent 60%),
    linear-gradient(180deg, #050816 0%, #0a1030 55%, #131a3f 100%);
  text-align: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
/* Il menu può essere più alto dello schermo del telefono: si scorre */
.screen-scroll {
  justify-content: flex-start;
  overflow-y: auto;
  touch-action: pan-y;
  gap: 14px;
}
.screen-transparent {
  background: rgba(4, 7, 20, 0.72);
  backdrop-filter: blur(3px);
}

.title {
  font-size: clamp(44px, 8vw, 96px);
  letter-spacing: 4px;
  color: var(--text);
  text-shadow: 0 0 24px rgba(53, 224, 255, 0.8), 0 4px 0 rgba(0,0,0,0.4);
}
.title span { color: var(--cyan); }
.title-compact { font-size: clamp(36px, 7vw, 72px); margin-top: 4px; }

.subtitle {
  font-size: clamp(16px, 2.4vw, 24px);
  opacity: 0.9;
  margin-top: -10px;
}

.menu-buttons { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

.btn {
  font-size: 20px;
  font-weight: 700;
  padding: 14px 30px;
  border-radius: 14px;
  border: 2px solid rgba(53, 224, 255, 0.55);
  background: rgba(12, 22, 52, 0.9);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}
.btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 22px rgba(53, 224, 255, 0.35);
  background: rgba(20, 34, 74, 0.95);
}
.btn-primary {
  background: linear-gradient(135deg, #0da9c9, #0b6fd6);
  border-color: rgba(255, 255, 255, 0.5);
}
.btn-small { font-size: 16px; padding: 10px 20px; }

.instructions {
  max-width: 560px;
  background: var(--panel);
  border: 1px solid rgba(53, 224, 255, 0.25);
  border-radius: 16px;
  padding: 18px 24px;
  text-align: left;
}
.instructions h3 { margin-bottom: 10px; color: var(--cyan); }
.instructions ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.instructions li { font-size: 16px; line-height: 1.35; }
.privacy-note { margin-top: 12px; font-size: 13px; opacity: 0.65; }
.instructions-kb-title { margin-top: 14px; font-size: 15px; color: var(--cyan); }
.instructions-kb { font-size: 14px; opacity: 0.85; line-height: 1.5; }

.best-score { font-size: 18px; color: var(--yellow); }

/* Classifica nel menu */
#lb-box {
  width: min(560px, 92vw);
  background: var(--panel);
  border: 1px solid rgba(255, 217, 59, 0.35);
  border-radius: 16px;
  padding: 14px 18px;
}
#lb-claim { font-size: 17px; margin-bottom: 10px; }
#lb-claim strong { color: var(--yellow); }
#lb-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}
#lb-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  padding: 3px 6px;
  border-radius: 8px;
}
#lb-list li:first-child:not(.lb-empty) {
  background: rgba(255, 217, 59, 0.12);
  font-weight: 800;
}
#lb-list .lb-pos { width: 26px; text-align: right; opacity: 0.8; }
#lb-list .lb-char { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; object-position: top; background: #223; }
#lb-list .lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-list .lb-score { font-weight: 700; color: var(--cyan); }
#lb-list .lb-empty { opacity: 0.7; justify-content: center; }
#lb-me { margin-top: 8px; font-size: 14px; color: var(--yellow); }

/* Nome utente */
#username-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  width: min(560px, 92vw);
  justify-content: center;
}
#username-input { min-width: 0; }
#username-row label { font-size: 16px; opacity: 0.9; white-space: nowrap; }
#username-input {
  flex: 1;
  max-width: 260px;
  font-size: 18px;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(53, 224, 255, 0.45);
  background: rgba(6, 12, 32, 0.9);
  color: var(--text);
  text-align: center;
}
#username-input:focus { outline: 2px solid var(--cyan); }
#btn-dice {
  font-size: 20px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(53, 224, 255, 0.35);
  background: rgba(12, 22, 52, 0.9);
  cursor: pointer;
}
.username-msg { font-size: 14px; color: #ff7b93; max-width: min(560px, 92vw); }

/* Selezione personaggio */
#char-select {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.char-card {
  width: 118px;
  padding: 10px 8px 8px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(10, 16, 38, 0.85);
  /* È un <button>: senza colore esplicito eredita il nero di sistema */
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.char-card img {
  width: 86px;
  height: 106px;
  object-fit: cover;
  object-position: top;
  border-radius: 10px;
  background: #d8dde6;
}
.char-card .char-name { font-size: 14px; font-weight: 800; margin-top: 6px; color: var(--text); }
.char-card .char-desc { font-size: 11.5px; color: #c3d3e8; line-height: 1.3; margin-top: 2px; }
.char-card:hover { transform: translateY(-2px); }
.char-card.selected {
  border-color: var(--card-color, var(--cyan));
  box-shadow: 0 0 16px color-mix(in srgb, var(--card-color, var(--cyan)) 55%, transparent);
}
.char-card.selected .char-name { color: var(--card-color, var(--cyan)); }

/* Bottone super (touch e mouse) */
#btn-super {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(140px + env(safe-area-inset-bottom));
  z-index: 35;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--yellow);
  background: radial-gradient(circle at 35% 30%, #4a3d10, #16120a);
  color: var(--yellow);
  font-size: 24px;
  line-height: 1.1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  animation: superglow 0.7s ease-in-out infinite alternate;
}
#btn-super span { font-size: 10px; font-weight: 900; letter-spacing: 1px; }

.loader {
  width: 46px;
  height: 46px;
  border: 4px solid rgba(53, 224, 255, 0.25);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Calibrazione */
#calib-video-wrap {
  width: min(560px, 80vw, 60vh);
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(53, 224, 255, 0.5);
  background: #000;
  flex-shrink: 0;
}
#calib-canvas { display: block; width: 100%; }
#calib-progress-wrap {
  width: min(560px, 80vw);
  height: 14px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
#calib-progress {
  height: 100%;
  width: 0%;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  transition: width 0.15s linear;
}
#calib-status { font-size: 17px; min-height: 24px; }

/* Conto alla rovescia */
#countdown-number {
  font-size: clamp(120px, 25vw, 260px);
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 40px rgba(53, 224, 255, 0.9);
  animation: pop 0.9s ease infinite;
}
@keyframes pop {
  0% { transform: scale(0.6); opacity: 0.2; }
  30% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 0.9; }
}

/* HUD */
#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(16px + env(safe-area-inset-top))
           calc(20px + env(safe-area-inset-right))
           16px
           calc(20px + env(safe-area-inset-left));
}
#hud-left { display: flex; flex-direction: column; gap: 10px; }
#hearts { font-size: 30px; letter-spacing: 4px; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6)); }

#super-bar-wrap {
  position: relative;
  width: 190px;
  height: 20px;
  border-radius: 10px;
  border: 1px solid rgba(255, 217, 59, 0.6);
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
#super-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffb63b, var(--yellow));
  transition: width 0.2s ease;
}
#super-bar-wrap.full { animation: superglow 0.7s ease-in-out infinite alternate; }
@keyframes superglow {
  from { box-shadow: 0 0 6px rgba(255, 217, 59, 0.5); }
  to { box-shadow: 0 0 20px rgba(255, 217, 59, 1); }
}
#super-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: #ffffff;
  /* Contorno scuro: leggibile anche sopra la barra gialla piena */
  text-shadow: 0 1px 3px rgba(0,0,0,0.95), 0 0 2px rgba(0,0,0,0.9), 0 -1px 2px rgba(0,0,0,0.7);
}

#hud-right { text-align: right; }
#score {
  font-size: 38px;
  font-weight: 900;
  color: var(--text);
  text-shadow: 0 0 14px rgba(53, 224, 255, 0.7);
}
#combo {
  font-size: 22px;
  font-weight: 800;
  color: var(--yellow);
  text-shadow: 0 0 10px rgba(255, 217, 59, 0.8);
}

#hud-center { flex: 1; display: flex; flex-direction: column; align-items: center; }

/* Barra vita del boss */
#boss-bar-wrap {
  margin-top: 6px;
  width: min(420px, 74vw);
  text-align: center;
  animation: bossin 0.4s ease;
}
@keyframes bossin { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#boss-name {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ff6b8f;
  text-shadow: 0 0 10px rgba(255, 59, 107, 0.9);
  margin-bottom: 4px;
}
#boss-bar-track {
  height: 16px;
  border-radius: 8px;
  border: 1px solid rgba(255, 79, 216, 0.7);
  background: rgba(0, 0, 0, 0.5);
  overflow: hidden;
  box-shadow: 0 0 14px rgba(255, 59, 107, 0.5);
}
#boss-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ff9f1c, #ff3b6b, #ff4fd8);
  transition: width 0.15s ease;
}
#wave-banner {
  margin-top: 8vh;
  font-size: clamp(30px, 5vw, 54px);
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--magenta);
  text-shadow: 0 0 22px rgba(255, 79, 216, 0.8);
  animation: wavein 0.5s ease;
}
@keyframes wavein {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Game over */
.gameover-title {
  font-size: clamp(50px, 9vw, 110px);
  color: var(--magenta);
  text-shadow: 0 0 30px rgba(255, 79, 216, 0.8);
  letter-spacing: 6px;
}
.final-score {
  font-size: clamp(40px, 6vw, 70px);
  font-weight: 900;
  color: var(--cyan);
  text-shadow: 0 0 20px rgba(53, 224, 255, 0.8);
}
.final-detail { font-size: 18px; opacity: 0.85; }

.hands-hint { font-size: 16px; opacity: 0.8; }
.hands-hint.attivo { color: var(--yellow); opacity: 1; }

.final-rank { font-size: 20px; font-weight: 700; color: var(--yellow); min-height: 26px; }

.instructions summary {
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  color: var(--cyan);
  text-align: center;
  list-style-position: inside;
}
.instructions h3 { margin-top: 10px; }

/* Schermi piccoli: HUD e anteprima webcam compatti */
@media (max-width: 640px) {
  #username-row label { width: 100%; }
  #username-input { max-width: 200px; }
  #hearts { font-size: 24px; letter-spacing: 2px; }
  #score { font-size: 28px; }
  #combo { font-size: 17px; }
  #super-bar-wrap { width: 140px; height: 17px; }
  #cam-pip { width: 110px; left: 10px; bottom: 10px; }
  #hud { padding: calc(10px + env(safe-area-inset-top)) 12px 10px; }
  .char-card { width: 100px; }
  .char-card img { width: 74px; height: 92px; }
  #wave-banner { margin-top: 12vh; }
}

/* Toast messaggi rapidi */
#toast {
  position: fixed;
  left: 50%;
  bottom: 26vh;
  transform: translateX(-50%);
  z-index: 40;
  background: var(--panel);
  border: 1px solid rgba(53, 224, 255, 0.4);
  padding: 10px 22px;
  border-radius: 12px;
  font-size: 20px;
  font-weight: 700;
  pointer-events: none;
  animation: toastin 0.25s ease;
}
@keyframes toastin {
  from { transform: translateX(-50%) translateY(14px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* Tasto "Fine": termina la partita in qualsiasi momento */
#hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#btn-end {
  pointer-events: auto;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 79, 216, 0.55);
  background: rgba(20, 10, 30, 0.7);
  color: #ffd0f2;
  cursor: pointer;
  margin-bottom: 2px;
  -webkit-tap-highlight-color: transparent;
}
#btn-end:hover { background: rgba(60, 20, 55, 0.85); }
#btn-end:active { transform: scale(0.95); }

/* Crediti a fondo pagina */
.made-by {
  max-width: min(560px, 92vw);
  margin-top: 10px;
  padding: 14px 16px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
  font-size: 12.5px;
  line-height: 1.5;
  color: rgba(234, 246, 255, 0.62);
}
.made-by p { margin: 4px 0; }
.made-by-line { font-size: 15px; font-weight: 800; color: rgba(234, 246, 255, 0.9); }
.made-by-line s { color: var(--magenta); text-decoration-thickness: 2px; }
.made-by a { color: var(--cyan); font-weight: 700; text-decoration: none; }
.made-by a:hover { text-decoration: underline; }
