:root {
  --navy: #1b4d6b;
  --navy-dark: #0f3048;
  --orange: #f39200;
  --red: #a3172e;
  --yellow: #f2c100;
  --green: #8cbf26;
  --blue: #2ba3d6;
  --white: #ffffff;
  --glass: rgba(255, 255, 255, 0.92);
  --shadow: 0 10px 30px rgba(10, 30, 50, 0.35);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0f3048;
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--navy-dark);
}

/* ---------- Palco ---------- */
.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #0f3048 url("../assets/Il_Teatro_Massimo_di_Palermo.jpg") center 35% / cover no-repeat;
}

.dancers {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}
/* Fallback (Safari): video MP4 con sfondo bianco fuso con lo sfondo */
.dancers.blend { mix-blend-mode: multiply; }

.avatar-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  z-index: 5;
}
.hud[hidden] { display: none; }

.brand {
  background: var(--glass);
  border-radius: 16px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
}
.brand img { display: block; height: 46px; width: auto; }

.score-box, .time {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--glass);
  border-radius: 16px;
  padding: 6px 20px;
  box-shadow: var(--shadow);
  min-width: 110px;
}
.label { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--orange); }
.value { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--navy); }
.score-box .value { font-size: 2.4rem; }

.right { display: flex; align-items: center; gap: 12px; }

/* ---------- Bottoni ---------- */
.btn {
  font-family: inherit;
  font-weight: 700;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 4px solid var(--yellow); outline-offset: 3px; }
.btn:disabled { opacity: 0.6; cursor: wait; transform: none; }

.btn-start {
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  padding: 16px 64px;
  color: #fff;
  background: linear-gradient(135deg, var(--orange), #ff6a00);
  box-shadow: 0 8px 0 #b55f00, var(--shadow);
}
.btn-stop {
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  padding: 14px 28px;
  color: #fff;
  background: var(--red);
  box-shadow: 0 5px 0 #6c0d1d, var(--shadow);
}

/* ---------- Energia ---------- */
.energy {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 4;
}
.energy[hidden] { display: none; }
.energy-track {
  width: 26px;
  height: 38vh;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 4px;
  display: flex;
  align-items: flex-end;
  box-shadow: var(--shadow);
}
.energy-fill {
  width: 100%;
  height: 0%;
  border-radius: 999px;
  background: linear-gradient(to top, var(--blue), var(--green), var(--yellow), var(--orange), var(--red));
  background-size: 100% 38vh;
  background-position: bottom;
  transition: height 0.12s linear;
}
.energy-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff;
  background: var(--navy);
  padding: 3px 8px;
  border-radius: 8px;
}

/* ---------- Voce ---------- */
.voice-chip {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 48, 72, 0.85);
  color: #fff;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 999px;
  z-index: 4;
  white-space: nowrap;
}
.voice-chip[hidden] { display: none; }
.voice-chip .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--red);
  animation: pulse 1.2s infinite;
}
.voice-chip.off .dot { background: #999; animation: none; }
@keyframes pulse { 50% { transform: scale(1.5); opacity: 0.5; } }

/* ---------- Feedback & countdown ---------- */
.feedback {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: clamp(2rem, 6vw, 4.5rem);
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 3px var(--navy);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--orange);
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  white-space: nowrap;
}
.feedback.show { animation: pop 1.1s ease-out forwards; }
@keyframes pop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5) rotate(-6deg); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(3deg); }
  40%  { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(6rem, 22vw, 16rem);
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 6px var(--navy);
  paint-order: stroke fill;
  text-shadow: 0 12px 0 var(--orange);
  pointer-events: none;
  z-index: 8;
}
.countdown.tick { animation: tick 0.9s ease-out; }
@keyframes tick { 0% { transform: scale(1.8); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { opacity: 0.2; } }

/* ---------- Telecamera ---------- */
.cam {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: min(26vw, 280px);
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  overflow: hidden;
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  background: #000;
  z-index: 4;
}
.cam[hidden] { display: none; }
.cam video, .cam canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.cam video { transform: scaleX(-1); }
.cam-tag {
  position: absolute;
  left: 8px; top: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  background: rgba(15, 48, 72, 0.8);
  padding: 2px 8px;
  border-radius: 6px;
}

/* ---------- Schermate ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(15, 48, 72, 0.35), rgba(15, 48, 72, 0.75));
  z-index: 10;
  overflow-y: auto;
}
.screen[hidden] { display: none; }

.card {
  width: min(560px, 100%);
  background: var(--glass);
  border-radius: 28px;
  padding: 28px 32px 30px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  border-top: 8px solid var(--orange);
}
.card-logo { width: min(340px, 85%); height: auto; }
.card h1, .card h2 {
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 700;
  color: var(--navy);
  margin: 6px 0 6px;
  line-height: 1.1;
}
.sub { font-size: 1.05rem; color: #34566c; margin-bottom: 16px; line-height: 1.4; }

.rules {
  list-style: none;
  text-align: left;
  display: grid;
  gap: 8px;
  margin: 0 auto 22px;
  max-width: 440px;
}
.rules li { display: flex; align-items: center; gap: 12px; font-size: 1rem; color: var(--navy-dark); }
.rules b {
  flex: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 0.95rem;
}
.rules li:nth-child(1) b { background: var(--red); }
.rules li:nth-child(2) b { background: var(--yellow); color: var(--navy-dark); }
.rules li:nth-child(3) b { background: var(--green); }
.rules li:nth-child(4) b { background: var(--blue); }

.status { min-height: 1.4em; margin-top: 16px; font-weight: 500; color: var(--navy); }
.status.error { color: var(--red); }
.best { margin-top: 6px; font-size: 0.95rem; color: #5a7486; }

.final-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  margin: 4px 0 6px;
}
.final-score span { font-size: 5rem; font-weight: 700; color: var(--orange); line-height: 1; font-variant-numeric: tabular-nums; }
.final-score small { font-size: 1.3rem; font-weight: 600; color: var(--navy); }
.stars { font-size: 2.6rem; letter-spacing: 6px; margin-bottom: 4px; }
.stars .on { color: var(--yellow); text-shadow: 0 2px 0 #b38f00; }
.stars .off { color: #d4dde3; }
#againBtn { margin-top: 18px; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .hud { padding: 10px; gap: 6px; flex-wrap: wrap; }
  .brand img { height: 30px; }
  .score-box, .time { min-width: 0; padding: 4px 12px; }
  .value { font-size: 1.4rem; }
  .score-box .value { font-size: 1.6rem; }
  .btn-stop { padding: 10px 16px; font-size: 1rem; }
  .energy { left: 8px; }
  .energy-track { width: 18px; height: 30vh; }
  .cam { width: 36vw; right: 10px; bottom: 56px; }
  .card { padding: 20px 18px 24px; }
  .btn-start { padding: 14px 40px; font-size: 1.35rem; }
}
