:root {
  --bg-0: #0d0b1f;
  --bg-1: #1a1438;
  --bg-2: #221a4a;
  --panel: #161231;
  --panel-2: #1f1840;
  --ink: #ece8ff;
  --ink-dim: #9b93c9;
  --accent: #7c5cff;
  --accent-2: #38d97b;
  --danger: #ff5964;
  --good: #38d97b;
  --line: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 800px at 20% -10%, #2a1f5c 0%, transparent 60%),
    radial-gradient(900px 700px at 110% 110%, #3a1f4a 0%, transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1));
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  max-width: 920px;
  margin: 0 auto;
  gap: 10px;
  padding: 10px;
}

/* ---------------- TOPBAR ---------------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 6px 0;
}
.topbar .brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
}
.topbar .brand .logo {
  color: var(--accent);
  font-size: 24px;
  text-shadow: 0 0 18px var(--accent);
}
.topbar .version {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-dim);
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- PLAY AREA ---------------- */
.playArea {
  flex: 1 1 auto;
  display: flex;
  gap: 14px;
  min-height: 0;
}

/* ---------------- AREA GIOCO ---------------- */
#gameWrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.03), rgba(0,0,0,0.25)),
    var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45), inset 0 0 0 1px rgba(255,255,255,0.03);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* ---------------- PANNELLO ---------------- */
#panel {
  flex: 0 0 250px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}

.hudRow { display: flex; gap: 10px; }

/* RIGA VITE */
.livesRow { gap: 0; }
.livesHud { width: 100%; text-align: left; }
.lives {
  font-size: 26px;
  line-height: 1;
  letter-spacing: 4px;
  margin-top: 4px;
  min-height: 26px;
}
.lives .heart        { color: #ff5964; text-shadow: 0 0 10px rgba(255,89,100,0.6); }
.lives .heart.empty  { color: #4a4068; text-shadow: none; }
.lives .heart.flash-life { animation: flashLife .5s ease; }
@keyframes flashLife { 0%{transform:scale(1.5);color:#ff8a91} 100%{transform:scale(1);color:#ff5964} }
.hud {
  flex: 1 1 0;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  text-align: center;
}
.lbl {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--ink-dim);
  font-weight: 700;
}
.val {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
#score.flash-good { animation: flashGood .4s ease; }
#score.flash-bad  { animation: flashBad  .4s ease; }
@keyframes flashGood { 0%{color:var(--good);transform:scale(1.25)} 100%{color:#fff;transform:scale(1)} }
@keyframes flashBad  { 0%{color:var(--danger);transform:scale(1.25)} 100%{color:#fff;transform:scale(1)} }

.controls { display: flex; gap: 10px; }
.ctrl {
  flex: 1;
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.ctrl:hover { background: rgba(124,92,255,0.25); }
.ctrl:active { transform: translateY(1px); }

#queue { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
#queue .lbl { margin-bottom: 8px; }
#queueItems {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
}
.qitem {
  width: 54px;
  height: 54px;
  background: rgba(255,255,255,0.04);
  border: 2px solid var(--line);
  border-radius: 12px;
  display: grid;
  place-items: center;
  position: relative;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.qitem.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,92,255,0.25), 0 0 22px rgba(124,92,255,0.45);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.08)} }
.qitem .tag {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 1px 6px;
  border-radius: 6px;
}
.qitem canvas { width: 40px; height: 40px; }

.legend {
  font-size: 11px;
  color: var(--ink-dim);
  line-height: 1.5;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.legend b { color: var(--ink); }
.legend .muted { color: #6f679a; margin-top: 2px; }

/* ---------------- OVERLAYS ---------------- */
#overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  background: rgba(8,6,20,0.78);
  backdrop-filter: blur(6px);
  pointer-events: auto;
  padding: 24px;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
.screen.hidden { display: none; }

.screen h1 {
  font-size: 64px;
  margin: 0;
  letter-spacing: 4px;
  background: linear-gradient(120deg, #7c5cff, #38d97b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 50px rgba(124,92,255,0.4);
}
.screen h2 {
  font-size: 42px;
  margin: 0;
  letter-spacing: 2px;
}
.screen .lead { color: var(--ink-dim); font-size: 16px; margin: 0; line-height: 1.5; }
.rules {
  list-style: none;
  padding: 14px 18px;
  margin: 6px 0;
  text-align: left;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink);
}
.rules li { padding-left: 4px; }
.rules b { color: #fff; }

.final { font-size: 26px; font-weight: 800; }
.final span { color: var(--accent-2); }
#bestLine { color: var(--ink-dim); margin: -4px 0 6px; }
#bestLine span { color: #fff; font-weight: 700; }

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 12px 28px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  cursor: pointer;
  transition: transform .1s, background .15s, box-shadow .15s;
  letter-spacing: 0.5px;
}
.btn:hover { background: rgba(255,255,255,0.12); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(120deg, var(--accent), #5a3fd6);
  border: none;
  box-shadow: 0 10px 26px rgba(124,92,255,0.4);
}
.btn.primary:hover { box-shadow: 0 12px 34px rgba(124,92,255,0.6); }
.btn.sm { padding: 6px 14px; font-size: 13px; }

/* ---------------- TOAST AGGIORNAMENTO ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: rgba(20, 16, 48, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1000;
  box-shadow: 0 14px 40px rgba(0,0,0,0.6);
  animation: toastIn .3s ease;
}
.toast.hidden { display: none; }
.toast span { font-size: 14px; color: var(--ink); }
@keyframes toastIn { from{opacity:0;transform:translate(-50%,12px)} to{opacity:1;transform:translate(-50%,0)} }

/* ---------------- RESPONSIVE ---------------- */
@media (max-width: 760px) {
  #app { padding: 6px; gap: 6px; }
  .topbar { padding: 2px 2px 0; }
  .topbar .brand { font-size: 18px; }
  .topbar .brand .logo { font-size: 20px; }

  .playArea { flex-direction: column; gap: 6px; }

  #gameWrap { flex: 1 1 auto; min-height: 0; }

  #panel {
    flex: 0 0 auto;
    padding: 8px;
    gap: 8px;
    /* su mobile: HUD compatte in fila + sequenza subito sotto il campo */
  }
  /* riorganizza il pannello: HUD in una riga, poi sequenza */
  .hudRow { gap: 6px; }
  .hud { padding: 4px 6px; }
  .hud .val { font-size: 16px; }
  .hud .lbl { font-size: 9px; }
  .controls { gap: 6px; }
  .ctrl { padding: 6px; font-size: 14px; }

  /* sequenza subito sotto il campo, compatta e orizzontale */
  #queue { order: -1; }
  #queue .lbl { margin-bottom: 4px; font-size: 9px; }
  #queueItems { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .qitem { width: 44px; height: 44px; }
  .qitem canvas { width: 32px; height: 32px; }

  .legend { display: none; }   /* su mobile nasconde la legenda per fare spazio */

  .screen h1 { font-size: 44px; }
}
