html, body {
    margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
    background: #3aa0d8; font-family: 'Segoe UI', Roboto, Arial, sans-serif;
    touch-action: none; -webkit-user-select: none; user-select: none;
    overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
  }
  #game { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

  /* ---------- HUD ---------- */
  #hud {
    position: fixed; top: 0; left: 0; right: 0;
    padding: calc(10px + env(safe-area-inset-top)) 12px 0 12px;
    display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap;
    pointer-events: none; z-index: 5; color: #fff;
    text-shadow: 0 2px 2px rgba(0,0,0,.35);
  }
  .hudBox {
    background: rgba(0,0,0,.35); border-radius: 14px; padding: 8px 14px;
    font-weight: 700; font-size: 18px; backdrop-filter: blur(4px);
  }
  #coinBox { display: flex; align-items: center; gap: 8px; }
  #coinIcon {
    width: 22px; height: 22px; border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff3a0, #f7c531 55%, #c58a00);
    box-shadow: 0 1px 2px rgba(0,0,0,.4); display: inline-block;
  }
  #coinCount { display: inline-block; min-width: 28px; transform-origin: center; }
  .pop { animation: hudPop .35s ease-out; }
  @keyframes hudPop {
    0%   { transform: scale(1); color: #fff; }
    40%  { transform: scale(1.4); color: #ffe66b; }
    100% { transform: scale(1); color: #fff; }
  }
  #hpBox { min-width: 150px; }
  #hpLabel { font-size: 13px; opacity: .9; margin-bottom: 4px; }
  #hpBar { width: 100%; height: 12px; background: rgba(0,0,0,.45); border-radius: 6px; overflow: hidden; }
  #hpFill { height: 100%; width: 100%; background: linear-gradient(#7bff7b, #2ecc40); border-radius: 6px; transition: width .15s ease-out; }
  #hpBox.hurt { animation: hurtFlash .3s ease-out; }
  @keyframes hurtFlash { 0% { background: rgba(255,40,40,.75); } 100% { background: rgba(0,0,0,.35); } }
  #midBoxes { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
  #zoneBox, #fireBox, #carryBox, #energyBox { font-size: 14px; }
  #energyBox { display: none; min-width: 116px; }
  #energyMini { display:block; margin-top:4px; width:100%; height:5px; border-radius:4px; overflow:hidden; background:rgba(0,0,0,.38); }
  #energyFill { display:block; height:100%; width:100%; border-radius:4px; background:linear-gradient(90deg,#5cff86,#d9ff78); transition:width .18s ease; }
  #energyBox.low { background: rgba(179,112,0,.60); }
  #energyBox.critical { background: rgba(170,35,35,.72); animation: energyPulse .8s ease-in-out infinite alternate; }
  @keyframes energyPulse { from { transform: scale(1); } to { transform: scale(1.05); } }

  #hint {
    position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 0; right: 0;
    text-align: center; color: #fff; font-weight: 600; font-size: 15px;
    text-shadow: 0 2px 3px rgba(0,0,0,.5); pointer-events: none; z-index: 5;
    transition: opacity .6s; padding: 0 20px;
  }
  #toast {
    position: fixed; left: 50%; bottom: calc(70px + env(safe-area-inset-bottom));
    width: max-content; max-width: min(360px, calc(100vw - 28px));
    transform: translate(-50%, 12px) scale(.96);
    background: rgba(0,0,0,.55); color: #fff; font-weight: 800; font-size: 13px; line-height: 1.22;
    padding: 8px 12px; border-radius: 13px; opacity: 0; pointer-events: none; z-index: 7;
    text-shadow: 0 1px 2px rgba(0,0,0,.5); transition: opacity .20s, transform .20s; text-align: center;
  }
  #toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

  /* ---------- Objective / tutorial ---------- */
  #objectivePanel {
    position: fixed; top: calc(72px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
    z-index: 6; width: min(480px, calc(100vw - 20px)); padding: 5px 9px 6px;
    border-radius: 11px; color: #fff; text-align: left; pointer-events: none;
    display: grid; grid-template-columns: auto minmax(0,1fr); grid-template-rows: auto 3px;
    align-items: center; column-gap: 8px; row-gap: 4px;
    background: linear-gradient(180deg, rgba(10,42,61,.80), rgba(6,28,43,.70));
    border: 1px solid rgba(255,255,255,.22); box-shadow: 0 5px 14px rgba(0,0,0,.15);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    transition: opacity .2s ease;
  }
  #objectiveTitle { font-size: 9px; font-weight: 900; letter-spacing: .8px; color: #ffe37d; white-space: nowrap; }
  #objectiveText { margin: 0; font-size: 11px; font-weight: 800; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #objectiveProgress { grid-column: 1 / -1; height: 3px; margin: 0; background: rgba(0,0,0,.30); border-radius: 4px; overflow: hidden; }
  #objectiveProgress > i { display:block; height:100%; width:0; background:#ffe37d; border-radius:4px; transition:width .18s ease; }
  .miniBar { display:block; width:72px; height:5px; margin:4px auto 0; background:rgba(0,0,0,.38); border-radius:4px; overflow:hidden; }
  .miniBar > i { display:block; height:100%; background:#ffe37d; border-radius:4px; }

  /* ---------- World labels ---------- */
  .worldLabel {
    position: fixed; left: 0; top: 0; transform: translate(-50%, -50%);
    color: #fff; font-weight: 800; font-size: 20px; text-align: center;
    text-shadow: 0 2px 3px rgba(0,0,0,.6); pointer-events: none; z-index: 4;
    line-height: 1; white-space: nowrap;
  }
  .worldLabel small { display: block; font-size: 10px; font-weight: 600; opacity: .95; margin-top: 3px; letter-spacing: .4px; }
  .worldLabel.bump { animation: labelBump .18s ease-out; }
  .worldLabel.locked { opacity: .75; font-size: 18px; }
  .worldLabel.building { font-size: 20px; }
  @keyframes labelBump { 0% { transform: translate(-50%,-50%) scale(1.35); } 100% { transform: translate(-50%,-50%) scale(1); } }

  /* ---------- Joystick ---------- */
  #joyZone { position: fixed; inset: 0; z-index: 3; touch-action: none; }
  #joyBase {
    position: fixed; width: 120px; height: 120px; border-radius: 50%;
    background: rgba(255,255,255,.18); border: 2px solid rgba(255,255,255,.45);
    transform: translate(-50%, -50%); pointer-events: none; z-index: 6; display: none;
  }
  #joyThumb {
    position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; border-radius: 50%;
    background: rgba(255,255,255,.85); box-shadow: 0 2px 8px rgba(0,0,0,.35);
    transform: translate(-50%, -50%);
  }

  /* ---------- Overlay ---------- */
  #overlay {
    position: fixed; inset: 0; background: rgba(20,10,30,.72); z-index: 10;
    display: none; align-items: center; justify-content: center; flex-direction: column;
    color: #fff; text-align: center; padding: 20px;
  }
  #overlay.show { display: flex; }
  #overlay h1 { font-size: 48px; margin: 0 0 8px 0; letter-spacing: 3px; text-shadow: 0 4px 10px rgba(0,0,0,.6); }
  #overlay p { margin: 0 0 26px 0; font-size: 18px; opacity: .9; }
  #retryBtn {
    font-size: 22px; font-weight: 800; padding: 16px 44px; border: none; border-radius: 40px;
    background: linear-gradient(#ffd34d, #f5a623); color: #3a2400; cursor: pointer;
    box-shadow: 0 6px 0 #b46f00, 0 10px 20px rgba(0,0,0,.4); letter-spacing: 1px;
    touch-action: manipulation;
  }
  #retryBtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #b46f00; }

  /* ---------- Visual refresh ---------- */
  :root {
    --glass: rgba(13, 35, 54, .72);
    --glass-border: rgba(255,255,255,.28);
    --gold: #ffd54f;
    --gold-dark: #d99000;
  }
  #game { filter: saturate(1.05) contrast(1.02); }
  #hud { padding-top: calc(12px + env(safe-area-inset-top)); transition: opacity .25s ease; }
  .hudBox {
    background: linear-gradient(180deg, rgba(21,56,80,.78), rgba(8,31,49,.72));
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 24px rgba(0,39,65,.16), inset 0 1px 0 rgba(255,255,255,.18);
    backdrop-filter: blur(10px) saturate(1.15);
    -webkit-backdrop-filter: blur(10px) saturate(1.15);
  }
  #coinIcon { border: 2px solid rgba(255,255,255,.55); box-shadow: 0 2px 5px rgba(73,44,0,.35), inset 0 2px 3px rgba(255,255,255,.55); }
  #hpBar { border: 1px solid rgba(255,255,255,.16); box-shadow: inset 0 2px 5px rgba(0,0,0,.25); }
  #hpFill { box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 0 9px rgba(73,255,110,.24); }
  .worldLabel {
    padding: 5px 8px; border-radius: 11px;
    background: linear-gradient(180deg, rgba(11,39,57,.34), rgba(11,39,57,.08));
    text-shadow: 0 2px 3px rgba(0,0,0,.72);
    filter: drop-shadow(0 4px 5px rgba(0,0,0,.15));
  }
  .worldLabel small { color: #eefaff; }
  #joyBase {
    background: radial-gradient(circle, rgba(255,255,255,.10) 0 42%, rgba(255,255,255,.20) 44% 100%);
    border: 2px solid rgba(255,255,255,.6);
    box-shadow: 0 8px 26px rgba(0,43,70,.22), inset 0 0 0 7px rgba(255,255,255,.05);
    backdrop-filter: blur(3px);
  }
  #joyThumb {
    background: radial-gradient(circle at 35% 30%, #ffffff, #d9f4ff 58%, #a9ddf2);
    border: 2px solid rgba(255,255,255,.72);
    box-shadow: 0 5px 12px rgba(0,35,56,.32), inset 0 1px 2px rgba(255,255,255,.9);
  }
  #hint {
    width: fit-content; max-width: min(760px, calc(100vw - 32px)); left: 50%; right: auto;
    transform: translateX(-50%); padding: 9px 16px; border-radius: 18px;
    background: rgba(6,31,49,.38); border: 1px solid rgba(255,255,255,.18);
    backdrop-filter: blur(6px);
  }
  #toast {
    background: linear-gradient(180deg, rgba(18,50,70,.92), rgba(7,28,44,.9));
    border: 1px solid rgba(255,255,255,.3);
    box-shadow: 0 14px 35px rgba(0,25,40,.3), inset 0 1px 0 rgba(255,255,255,.16);
  }

  /* ---------- Start screen ---------- */
  #startScreen {
    position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center;
    padding: max(22px, env(safe-area-inset-top)) 20px max(22px, env(safe-area-inset-bottom));
    color: #fff; text-align: center; overflow: hidden;
  }
  #startScreen.show { display: flex; }
  #startScreen::before {
    content: ''; position: absolute; inset: 0;
    background:
      radial-gradient(circle at 50% 36%, rgba(117,228,255,.22), transparent 34%),
      linear-gradient(180deg, rgba(5,40,65,.16), rgba(3,31,51,.56));
    backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  }
  #startPanel {
    position: relative; width: min(460px, calc(100vw - 34px));
    padding: 30px 26px 24px; border-radius: 30px;
    background: linear-gradient(155deg, rgba(18,60,82,.88), rgba(7,32,49,.86));
    border: 1px solid rgba(255,255,255,.34);
    box-shadow: 0 24px 70px rgba(0,25,44,.42), inset 0 1px 0 rgba(255,255,255,.2);
    backdrop-filter: blur(14px) saturate(1.15); -webkit-backdrop-filter: blur(14px) saturate(1.15);
  }
  #startBadge {
    display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border-radius: 999px;
    background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
    font-size: 11px; font-weight: 800; letter-spacing: 1.6px; color: #dff8ff;
  }
  #gameVersion { display: inline-block; margin: 0 0 10px; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 950; letter-spacing: 1.8px; color: #3d2a00; background: linear-gradient(180deg,#fff09a,#ffc83d); border: 1px solid rgba(255,255,255,.72); box-shadow: 0 5px 0 rgba(171,103,0,.78), 0 10px 24px rgba(0,0,0,.22); opacity: 1; }
  #startTitle {
    margin: 12px 0 4px; font-size: clamp(38px, 10vw, 62px); line-height: .95; font-weight: 950;
    letter-spacing: -2px; text-shadow: 0 6px 0 rgba(0,52,79,.28), 0 12px 30px rgba(0,20,35,.28);
  }
  #startTitle span { color: #ffe477; }
  #startSub { margin: 12px auto 24px; max-width: 340px; color: rgba(238,250,255,.84); font-size: 14px; line-height: 1.45; }
  .startBtn {
    width: 100%; min-height: 58px; margin-top: 12px; border: 0; border-radius: 18px;
    font: 900 17px/1 'Segoe UI', Roboto, Arial, sans-serif; letter-spacing: .7px; cursor: pointer;
    touch-action: manipulation; transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
  }
  .startBtn:active { transform: translateY(3px) scale(.99); }
  #startNewBtn {
    background: linear-gradient(180deg, #ffe77a, #ffc33e); color: #3d2a00;
    box-shadow: 0 7px 0 #cf8400, 0 14px 28px rgba(0,22,36,.22);
  }
  #startContinueBtn {
    background: linear-gradient(180deg, #7ce5ff, #42bde8); color: #06344b;
    box-shadow: 0 7px 0 #1686ad, 0 14px 28px rgba(0,22,36,.2);
  }
  #continueInfo { margin-top: 12px; min-height: 18px; font-size: 12px; color: rgba(224,247,255,.72); }
  #startTip { margin-top: 18px; font-size: 11px; color: rgba(224,247,255,.56); }
  body.menuOpen #hud, body.menuOpen #hint, body.menuOpen #worldLabels, body.menuOpen #objectivePanel { opacity: 0; pointer-events: none; }
  body.menuOpen #joyZone { pointer-events: none; }

  @media (max-width: 680px) {
    #hud { gap: 4px; padding-top: calc(7px + env(safe-area-inset-top)); padding-left: 7px; padding-right: 7px; }
    .hudBox { border-radius: 10px; padding: 5px 8px; font-size: 13px; }
    #coinBox { gap: 5px; }
    #coinIcon { width: 18px; height: 18px; border-width: 1px; }
    #coinCount { min-width: 20px; }
    #hpBox { min-width: 108px; padding: 5px 8px; }
    #hpLabel { font-size: 10px; margin-bottom: 2px; line-height: 1; }
    #hpBar { height: 7px; border-radius: 4px; }
    #midBoxes { order: 3; width: 100%; gap: 4px; flex-wrap: nowrap; }
    #zoneBox, #fireBox, #carryBox, #energyBox { font-size: 9.5px; flex: 1 1 auto; min-width: 0; padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #energyMini { height: 3px; margin-top: 2px; }
    #startPanel { padding: 26px 20px 21px; border-radius: 25px; }
    .worldLabel { font-size: 14px; }
    .worldLabel small { font-size: 8px; }
    #objectivePanel { top: calc(65px + env(safe-area-inset-top)); width: calc(100vw - 14px); padding: 4px 7px 5px; column-gap: 6px; row-gap: 3px; }
    #objectiveTitle { font-size: 8px; letter-spacing: .5px; }
    #objectiveText { font-size: 9.5px; }
    #toast { bottom: calc(62px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); font-size: 12px; padding: 7px 10px; border-radius: 11px; }
  }


/* V43.3 - diagnostica visiva nemici */
#debugBtn {
  position: fixed;
  right: max(9px, env(safe-area-inset-right));
  top: calc(118px + env(safe-area-inset-top));
  z-index: 45;
  min-width: 64px;
  height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 11px;
  background: rgba(9,24,34,.86);
  color: #dff8ff;
  font: 900 11px/1 'Segoe UI', Roboto, Arial, sans-serif;
  letter-spacing: .8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.28);
  touch-action: manipulation;
}
#debugBtn.on {
  color: #281d00;
  background: #ffe36e;
  border-color: #fff2a8;
}
#debugPanel {
  display: none;
  position: fixed;
  right: max(9px, env(safe-area-inset-right));
  top: calc(158px + env(safe-area-inset-top));
  z-index: 44;
  width: min(410px, calc(100vw - 18px));
  max-height: min(52vh, 430px);
  overflow: auto;
  padding: 9px 10px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,227,110,.72);
  background: rgba(4,15,22,.92);
  box-shadow: 0 9px 26px rgba(0,0,0,.38);
  color: #effaff;
  pointer-events: none;
}
#debugPanel.show { display: block; }
#debugTitle {
  margin-bottom: 5px;
  color: #ffe36e;
  font: 900 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .5px;
}
#debugText {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: 700 9.5px/1.28 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #d9f6ff;
}
body.menuOpen #debugPanel { display: none; }
@media (max-width: 680px) {
  #debugBtn { top: calc(102px + env(safe-area-inset-top)); height: 31px; min-width: 58px; padding: 0 8px; font-size: 10px; }
  #debugPanel { top: calc(138px + env(safe-area-inset-top)); width: calc(100vw - 18px); max-height: 46vh; }
  #debugText { font-size: 8.5px; }
}

/* V44: diagnostica disponibile solo con ?debug=1, niente spazio UI perso in gioco normale */
.devOnly { display: none !important; }
body.debugEnabled #debugBtn { display: block !important; }
body.debugEnabled #debugPanel.show { display: block !important; }
