:root {
  --cyan: #2ee6ff;
  --mag: #ff3df0;
  --amber: #ffb52e;
  --ink: #d8f6ff;
  --bg: #04050d;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 30%, #101536 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: "Bahnschrift", "Segoe UI", system-ui, sans-serif;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
#frame {
  width: min(100vw, calc((100vh - 76px) * 9 / 7));
  width: min(100vw, calc((100dvh - 76px) * 9 / 7));
  display: flex; flex-direction: column; gap: 8px; padding: 0 8px;
}

/* ---------- HUD ---------- */
#hud { display: flex; justify-content: space-between; align-items: flex-end; height: 52px; padding: 0 4px; }
.hud-block { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hud-block:nth-child(n+3) { align-items: flex-end; }
.lbl { font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--mag); text-shadow: 0 0 8px var(--mag); }
.val { font-size: clamp(18px, 3.4vw, 26px); font-weight: 700; letter-spacing: .12em; font-variant-numeric: tabular-nums;
  color: #fff; text-shadow: 0 0 6px var(--cyan), 0 0 18px var(--cyan); min-height: 30px; display: flex; align-items: center; gap: 4px; }
.life { width: 30px; height: 28px; filter: drop-shadow(0 0 5px var(--cyan)); transition: opacity .3s, filter .3s; }
.life.lost { opacity: .16; filter: none; }

/* ---------- Stage ---------- */
#stage {
  position: relative; border-radius: 10px; overflow: hidden;
  border: 1px solid rgba(46, 230, 255, .5);
  box-shadow: 0 0 26px rgba(46, 230, 255, .35), 0 0 70px rgba(255, 61, 240, .18), inset 0 0 40px rgba(255, 61, 240, .1);
}
#game { display: block; width: 100%; aspect-ratio: 9 / 7; }

/* ---------- Sagome SVG ---------- */
.hull { fill: currentColor; fill-opacity: .16; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.flex { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transform-box: fill-box; transform-origin: center; transition: transform .12s; }
.eye { fill: #fff; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
#enemies.f2 .flex { transform: scale(1.16, .62); }
.shield { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-dasharray: 5 4; opacity: .85; }
.cell { fill: #38ffb0; fill-opacity: .5; stroke: #38ffb0; stroke-width: .8; }
#boss .hull { stroke-width: 3; }
#boss .flex { stroke-width: 3; }
#boss.hit .hull { fill-opacity: .8; }
.boss-core { fill: #fff; stroke: #ff2e6e; stroke-width: 3; }
.popup { font: 700 15px "Bahnschrift", "Segoe UI", sans-serif; text-anchor: middle; letter-spacing: .08em; }

/* ---------- Overlay ---------- */
#overlay {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(8px, 2.2vh, 20px); padding: 16px; text-align: center;
  background: rgba(4, 5, 13, .74); cursor: pointer;
}
#overlay.on { display: flex; }
#overlay h1 {
  font-size: clamp(30px, 8vw, 76px); font-weight: 700; letter-spacing: .2em; margin-right: -.2em; color: #fff; line-height: 1;
  text-shadow: 0 0 6px #fff, 0 0 18px var(--cyan), 0 0 42px var(--cyan), 0 0 90px var(--mag);
}
#overlay h1.bad { text-shadow: 0 0 6px #fff, 0 0 18px #ff2e6e, 0 0 46px #ff2e6e; }
#overlay h1.good { text-shadow: 0 0 6px #fff, 0 0 18px #4dff9a, 0 0 46px #4dff9a, 0 0 90px var(--cyan); }
#overlay .sub { font-size: clamp(12px, 2vw, 17px); letter-spacing: .3em; text-transform: uppercase; color: var(--mag); text-shadow: 0 0 10px var(--mag); }
#overlay .big { font-size: clamp(18px, 3.4vw, 30px); letter-spacing: .14em; color: #fff; text-shadow: 0 0 12px var(--cyan); font-variant-numeric: tabular-nums; }
#overlay .legend { display: flex; gap: clamp(10px, 3vw, 30px); flex-wrap: wrap; justify-content: center; }
#overlay .legend div { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; letter-spacing: .12em; }
#overlay .legend svg { width: 54px; height: 44px; overflow: visible; filter: drop-shadow(0 0 6px currentColor); }
#overlay .keys { font-size: clamp(11px, 1.7vw, 14px); letter-spacing: .16em; line-height: 1.9; opacity: .85; }
#overlay kbd { font: inherit; padding: 2px 8px; border: 1px solid var(--cyan); border-radius: 4px; color: #fff; box-shadow: 0 0 8px rgba(46, 230, 255, .6); }
#overlay .go { font-size: clamp(13px, 2.2vw, 19px); letter-spacing: .26em; color: var(--amber); text-shadow: 0 0 12px var(--amber); animation: blink 1.1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: .25; } }

#banner { position: absolute; left: 0; right: 0; top: 36%; text-align: center; pointer-events: none; opacity: 0; }
#banner.show { animation: banner 2s ease-out forwards; }
#bannerTitle { font-size: clamp(24px, 6vw, 54px); font-weight: 700; letter-spacing: .3em; margin-right: -.3em; color: #fff; text-shadow: 0 0 8px #fff, 0 0 22px var(--cyan), 0 0 50px var(--cyan); }
#bannerSub { margin-top: 8px; font-size: clamp(12px, 2.2vw, 18px); letter-spacing: .34em; color: var(--mag); text-shadow: 0 0 10px var(--mag); }
#banner.alert #bannerTitle { text-shadow: 0 0 8px #fff, 0 0 22px #ff2e6e, 0 0 50px #ff2e6e; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.5); }
  15% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(.96); }
}
#pauseBox { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(4, 5, 13, .6);
  font-size: clamp(26px, 6vw, 56px); font-weight: 700; letter-spacing: .4em; color: #fff; text-shadow: 0 0 20px var(--cyan), 0 0 50px var(--cyan); cursor: pointer; }
#pauseBox.on { display: flex; }

/* ---------- Comandi touch ---------- */
#touch { display: none; gap: 10px; justify-content: space-between; padding-bottom: 6px; }
#touch button {
  flex: 1; height: 56px; font: 700 18px "Bahnschrift", "Segoe UI", sans-serif; letter-spacing: .14em; color: #fff;
  background: rgba(46, 230, 255, .08); border: 1px solid var(--cyan); border-radius: 10px; box-shadow: 0 0 12px rgba(46, 230, 255, .4);
  touch-action: none;
}
#touch button.fire { flex: 1.6; border-color: var(--mag); background: rgba(255, 61, 240, .1); box-shadow: 0 0 12px rgba(255, 61, 240, .45); }
#touch button:active { background: rgba(255, 255, 255, .22); }
@media (pointer: coarse) {
  #touch { display: flex; }
  #frame { width: min(100vw, calc((100dvh - 150px) * 9 / 7)); }
}
@media (prefers-reduced-motion: reduce) {
  #overlay .go { animation: none; }
  #banner.show { animation-timing-function: linear; }
}

/* ---------- Versione 3D ---------- */
#game { height: auto; background: #03040c; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#bossBar { position: absolute; left: 28%; right: 28%; top: 12px; height: 10px; display: none; border: 1.5px solid #ff2e6e; border-radius: 6px;
  box-shadow: 0 0 12px #ff2e6e, inset 0 0 6px rgba(255, 46, 110, .5); pointer-events: none; }
#bossBar.on { display: block; }
#bossFill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff2e6e, #ff3df0); border-radius: 4px; box-shadow: 0 0 10px #ff2e6e; }
#overlay { background: rgba(4, 5, 13, .52); }
#overlay .err { max-width: 520px; font-size: 15px; line-height: 1.6; letter-spacing: .06em; }
