:root {
  --notte: #0f3324;
  --foglia: #2f9e4f;
  --arancio: #ff8a1f;
  --arancio-scuro: #c2410c;
  --crema: #fff4dc;
  --inchiostro: #2a1406;
  --sx: env(safe-area-inset-left, 0px);
  --dx: env(safe-area-inset-right, 0px);
  --su: env(safe-area-inset-top, 0px);
  --giu: env(safe-area-inset-bottom, 0px);
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--notte); color: var(--crema);
  font-family: var(--font);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overscroll-behavior: none;
}
canvas#scena { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; touch-action: manipulation; cursor: pointer; }

/* ——— HUD ——— */
/* sopra lo strato dei comandi: il tasto pausa deve ricevere il tocco */
#hud {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  padding: calc(10px + var(--su)) calc(16px + var(--dx)) 0 calc(16px + var(--sx));
  display: flex; justify-content: space-between; align-items: flex-start;
}
.hud-sx, .hud-dx { display: flex; gap: 14px; align-items: center; }
.hud-sx { flex-direction: column; align-items: flex-start; gap: 4px; }
.contatore {
  display: flex; align-items: center; gap: 8px;
  font-weight: 900; font-size: 30px; letter-spacing: .5px;
  color: #fff; -webkit-text-stroke: 1.5px var(--inchiostro);
  text-shadow: 0 3px 0 var(--inchiostro), 0 4px 10px rgba(0,0,0,.35);
  transition: transform .15s;
}
.contatore.piccolo { font-size: 20px; }
.contatore.pulsa { transform: scale(1.25); }
.ico { display: inline-block; width: 30px; height: 30px; flex: none; }
.piccolo .ico { width: 20px; height: 20px; }
.ico-frutto {
  border-radius: 50% 50% 46% 46%;
  background: radial-gradient(circle at 35% 30%, #ffe08a 0 18%, #ffa21f 45%, #e8590c 100%);
  border: 2px solid var(--inchiostro);
  position: relative;
}
.ico-frutto::after { content: ""; position: absolute; width: 10px; height: 6px; background: #3fbf4a; border: 1.5px solid var(--inchiostro); border-radius: 0 70% 0 70%; top: -6px; left: 50%; }
.ico-cassa { background: #c98a46; border: 3px solid #7a4a1f; border-radius: 3px; background-image: linear-gradient(45deg, transparent 44%, #7a4a1f 44% 56%, transparent 56%), linear-gradient(-45deg, transparent 44%, #7a4a1f 44% 56%, transparent 56%); }
.ico-vita { border-radius: 50%; background: radial-gradient(circle at 50% 70%, #f6e3c4 0 28%, transparent 29%), #d9532b; border: 2px solid var(--inchiostro); position: relative; }
.ico-vita::before, .ico-vita::after { content: ""; position: absolute; top: -5px; width: 10px; height: 12px; background: #d9532b; border: 2px solid var(--inchiostro); border-bottom: 0; border-radius: 50% 50% 0 0; }
.ico-vita::before { left: 0; transform: rotate(-25deg); }
.ico-vita::after { right: 0; transform: rotate(25deg); }
.ico-tempo { border-radius: 50%; border: 3px solid var(--crema); position: relative; }
.ico-tempo::after { content: ""; position: absolute; left: 50%; top: 4px; width: 3px; height: 9px; background: var(--crema); transform-origin: bottom; }

.b-pausa {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 14px;
  background: rgba(15, 51, 36, .55); border: 2px solid rgba(255,255,255,.5);
  display: flex; gap: 6px; align-items: center; justify-content: center;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.b-pausa i { display: block; width: 6px; height: 18px; border-radius: 2px; background: #fff; }

/* ——— comandi touch ——— */
#comandi { position: fixed; inset: 0; z-index: 1; touch-action: none; }
#stick {
  position: fixed; left: calc(120px + var(--sx)); top: calc(100% - 110px - var(--giu));
  width: 132px; height: 132px; margin: -66px 0 0 -66px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.10), rgba(255,255,255,.05));
  border: 3px solid rgba(255,255,255,.35);
  opacity: .55; transition: opacity .15s;
  pointer-events: none;
}
#stick.attivo { opacity: 1; transition: none; }
#stick-pomo {
  position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px;
  border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff, #d9e6e0);
  box-shadow: 0 4px 10px rgba(0,0,0,.3);
}
.tasto {
  position: fixed; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 15px; letter-spacing: 1px; color: #fff;
  -webkit-text-stroke: .5px rgba(0,0,0,.4);
  border: 3px solid rgba(255,255,255,.7);
  box-shadow: 0 6px 0 rgba(0,0,0,.25), inset 0 -6px 0 rgba(0,0,0,.15);
  transition: transform .06s;
  pointer-events: none;
}
.tasto.premuto { transform: scale(.9) translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.25), inset 0 -3px 0 rgba(0,0,0,.15); }
.tasto.salto { width: 104px; height: 104px; right: calc(26px + var(--dx)); bottom: calc(24px + var(--giu)); background: rgba(47, 158, 79, .78); }
.tasto.giro { width: 84px; height: 84px; right: calc(142px + var(--dx)); bottom: calc(66px + var(--giu)); background: rgba(255, 138, 31, .8); }

/* ——— avvisi in gioco ——— */
.avviso {
  position: fixed; z-index: 2; left: 50%; top: 26%; transform: translate(-50%, -50%) scale(.6);
  font-weight: 900; font-size: 38px; color: #fff; -webkit-text-stroke: 2px var(--inchiostro);
  text-shadow: 0 4px 0 var(--inchiostro); opacity: 0; pointer-events: none; white-space: nowrap;
  transition: opacity .2s, transform .25s cubic-bezier(.3,1.6,.5,1);
}
.avviso.su { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ——— schermate ——— */
.schermo {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(16px + var(--su)) calc(24px + var(--dx)) calc(16px + var(--giu)) calc(24px + var(--sx));
  text-align: center; gap: 14px; z-index: 3;
}
.velo { background: rgba(10, 30, 22, .62); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.menu {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: 1fr auto; align-items: center;
  justify-items: start; text-align: left;
  background: linear-gradient(90deg, rgba(10,30,22,.6), rgba(10,30,22,0) 55%);
}
.menu .marchio { grid-column: 1; grid-row: 1; }
.menu .azioni { grid-column: 1; grid-row: 1; align-self: end; margin-bottom: 4px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.menu .guida { grid-column: 1 / span 2; grid-row: 2; margin: 0; font-size: 14px; opacity: .9; }
.marchio { align-self: start; margin-top: 6px; }
h1 {
  margin: 0; font-weight: 900; font-size: 64px; line-height: .88; letter-spacing: 1px;
  color: var(--arancio); -webkit-text-stroke: 3px var(--inchiostro);
  text-shadow: 0 6px 0 var(--inchiostro), 0 10px 22px rgba(0,0,0,.4);
  transform: rotate(-3deg); transform-origin: left;
}
h1 span { color: #ffd43b; font-size: 76px; }
h2 { margin: 0; font-weight: 900; font-size: 44px; color: #ffd43b; -webkit-text-stroke: 2px var(--inchiostro); text-shadow: 0 5px 0 var(--inchiostro); }
.sotto { margin: 8px 0 0; font-size: 16px; font-weight: 700; opacity: .95; text-shadow: 0 2px 4px rgba(0,0,0,.5); }
.bottone {
  min-width: 150px; padding: 12px 22px; border-radius: 16px; font-weight: 900; font-size: 18px;
  background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.55);
}
.bottone.grande {
  font-size: 26px; padding: 14px 40px; background: var(--arancio); color: #fff; border: 3px solid var(--inchiostro);
  -webkit-text-stroke: 1px var(--inchiostro);
  box-shadow: 0 6px 0 var(--inchiostro);
}
.bottone:active { transform: translateY(3px); }
.bottone.grande:active { box-shadow: 0 3px 0 var(--inchiostro); }
.colonna { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.riga { display: flex; gap: 14px; align-items: center; }
.record { margin: 0; font-size: 14px; font-weight: 700; opacity: .9; }
.suggerimento { margin: 0; font-size: 13px; max-width: 360px; background: rgba(0,0,0,.35); padding: 6px 10px; border-radius: 10px; }
.riepilogo { display: flex; gap: 34px; }
.riepilogo div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.riepilogo b { font-size: 30px; font-weight: 900; }
.riepilogo small { font-size: 13px; opacity: .8; }
.gemma { margin: 0; font-weight: 900; color: #ff9ff0; font-size: 18px; }

.ruota, .caricamento, .errore {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--notte); text-align: center; padding: 24px;
}
.ruota { display: none; font-weight: 800; font-size: 20px; gap: 18px; }
.telefono { width: 46px; height: 82px; border: 4px solid var(--crema); border-radius: 12px; animation: gira 1.8s ease-in-out infinite; }
@keyframes gira { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (max-width: 900px) { .ruota { display: flex; } }
.caricamento p { font-weight: 800; font-size: 18px; opacity: .9; }
.errore { z-index: 11; font-size: 15px; white-space: pre-wrap; }

@media (max-height: 360px) {
  h1 { font-size: 50px; } h1 span { font-size: 60px; }
  .tasto.salto { width: 92px; height: 92px; } .tasto.giro { width: 74px; height: 74px; right: calc(130px + var(--dx)); }
}
