/* =========================================================
   Reset di base + layout a tutto schermo
   ========================================================= */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0f14;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Evita il "rubber band" e l'evidenziazione su touch */
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

#app { position: fixed; inset: 0; }
#app canvas { display: block; }

/* =========================================================
   Splash iniziale (schermo bianco + logo, poi dissolvenza)
   ========================================================= */
#splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: radial-gradient(circle at 50% 38%, #eaf2fb, #cbdcee);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.8s ease;
  cursor: pointer;
}
#splash.hide { opacity: 0; pointer-events: none; }

/* --- Porta d'ingresso: "Clicca per entrare" (è anche il gesto che sblocca l'audio iOS) --- */
.gate { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.gate-frame {
  perspective: 1400px;
  width: min(60vw, 270px);
  aspect-ratio: 3 / 5;
  background: linear-gradient(#e4ebf3, #c2cedb);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 24px 60px rgba(31, 111, 208, 0.28);
}
.gate-door {
  position: relative;
  width: 100%; height: 100%;
  border-radius: 7px;
  background: linear-gradient(135deg, #356cb6, #1f4f8f);
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.6, 0, 0.2, 1), box-shadow 0.75s ease;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.18);
}
.gate-logo { width: 68%; filter: brightness(0) invert(1); opacity: 0.95; }
.gate-knob {
  position: absolute; right: 12px; top: 50%;
  width: 13px; height: 13px; margin-top: -6px;
  border-radius: 50%;
  background: #ffe9a8; box-shadow: 0 0 6px rgba(0, 0, 0, 0.35);
}
.gate-cta {
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  font-size: clamp(15px, 4.2vw, 22px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #1f6fd0;
}
#splash.ready .gate-cta { animation: gate-pulse 1.4s ease-in-out infinite; }
@keyframes gate-pulse {
  0%, 100% { opacity: 0.5; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}
#splash.open .gate-frame { background: #0a0f16; }
#splash.open .gate-door { transform: rotateY(-108deg); box-shadow: inset -30px 0 50px rgba(0, 0, 0, 0.6); }
#splash.open .gate-cta { opacity: 0; transition: opacity 0.25s; }

/* =========================================================
   Layer azzurrino + footer (logo, nome azienda, P.IVA)
   ========================================================= */
#site-overlay {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;        /* non blocca i clic sulla scena/UI */
  background: linear-gradient(to top, rgb(0 0 0 / 50%) 0%, rgb(0 0 0 / 35%) 5%, rgba(46, 96, 170, 0) 13%);
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}
.footer-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px 10px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.footer-inner img {
  height: 26px;
  padding: 3px 7px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 7px;
}
@media (max-width: 640px) {
  .footer-inner { font-size: 11px; padding: 0 12px 8px; }
  .footer-inner img { height: 22px; }
}
@keyframes splash-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: none; }
}

/* =========================================================
   Contenitori UI in sovrimpressione
   ========================================================= */
.overlay-controls {
  position: fixed;
  bottom: 28px;
  left: 28px;
  z-index: 10;
}

/* =========================================================
   D-PAD (frecce desktop)
   Griglia 3x3 con le 4 frecce disposte a croce.
   ========================================================= */
#dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
}

.arrow-btn {
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.10);
  color: #e8f0ff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: transform .08s ease, background .12s ease, box-shadow .12s ease;
}

.arrow-btn:hover { background: rgba(255, 255, 255, 0.18); }

/* Stato "premuto": applicato sia dal click reale sia dalla tastiera fisica
   (vedi controls.js -> classe .active aggiunta/rimossa via JS). */
.arrow-btn.active {
  background: #4f9dff;
  color: #fff;
  transform: scale(0.92);
  box-shadow: 0 0 18px rgba(79, 157, 255, 0.7);
}

/* Posizionamento delle frecce nella griglia 3x3 */
.arrow-up    { grid-column: 2; grid-row: 1; }
.arrow-left  { grid-column: 1; grid-row: 2; }
.arrow-down  { grid-column: 2; grid-row: 2; }
.arrow-right { grid-column: 3; grid-row: 2; }

/* =========================================================
   Zona joystick (mobile)
   ========================================================= */
#joystick-zone {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  touch-action: none;
}

/* Pomello del joystick (creato via JS, centrato nella zona). */
#joystick-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;       /* centra rispetto al punto 50%/50% */
  border-radius: 50%;
  background: rgba(79, 157, 255, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;          /* gli eventi li gestisce la zona */
  transition: transform 0.05s linear;
}

/* =========================================================
   Toggle desktop/mobile.
   Di default mostriamo il d-pad e nascondiamo il joystick.
   La classe .touch-device sul <body> (impostata da JS) inverte i ruoli.
   ========================================================= */
#joystick-zone { display: none; }
#dpad         { display: grid; }

body.touch-device #joystick-zone { display: block; }
body.touch-device #dpad          { display: none; }

/* =========================================================
   HUD
   ========================================================= */
#hud {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(10, 16, 24, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: #cdd9ec;
  font-size: 13px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}
#hud strong { color: #fff; font-size: 14px; }

/* =========================================================
   Pannello impostazioni (tasto Y)
   ========================================================= */
#settings-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  width: 248px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(14, 20, 28, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e7eef8;
  font-size: 13px;
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
#settings-panel.hidden { display: none; }

.sp-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 12px;
}
.sp-hint { font-weight: 400; font-size: 11px; color: #9fb0c4; }
.sp-hint b { color: #4f9dff; }

.sp-group {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 8px 10px 10px;
  margin: 12px 0 0;
}
.sp-group legend { padding: 0 6px; font-weight: 600; color: #bcd0e8; }

.sp-row { margin: 8px 0; }
.sp-row label { display: block; margin-bottom: 4px; color: #cdd9ec; }
.sp-row b { color: #fff; }
.sp-row input[type="range"] { width: 100%; accent-color: #4f9dff; }
.sp-row select {
  width: 100%;
  padding: 5px 6px;
  border-radius: 8px;
  background: #1b2735;
  color: #e7eef8;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.sp-inline { display: flex; align-items: center; justify-content: space-between; }
.sp-inline label { margin: 0; }
.sp-inline input[type="color"] {
  width: 42px; height: 26px; padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px; background: none; cursor: pointer;
}

/* =========================================================
   Overlay "entrata" (dissolvenza al nero)
   ========================================================= */
#enter-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
#enter-overlay.show { opacity: 1; pointer-events: auto; }

#enter-content {
  text-align: center;
  color: #fff;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#enter-overlay.black #enter-content { opacity: 1; }

#enter-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 26px;
}
#enter-body { margin-bottom: 22px; }
#enter-body .enter-video {
  width: min(86vw, 960px);
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
#enter-body p {
  max-width: 720px;
  margin: 0 auto;
  font-size: 16px;
  line-height: 1.5;
  color: #dfe6ef;
}

/* Menu "stile gioco" (quando un custom ha più contenuti) */
.enter-menu {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(86vw, 420px);
  margin: 0 auto;
}
.menu-btn {
  padding: 18px 24px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
  background: linear-gradient(180deg, rgba(79,157,255,0.25), rgba(79,157,255,0.12));
  border: 1.5px solid rgba(120, 180, 255, 0.6);
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.menu-btn:hover, .menu-btn:active {
  transform: translateY(-2px);
  background: linear-gradient(180deg, rgba(79,157,255,0.45), rgba(79,157,255,0.22));
  box-shadow: 0 8px 24px rgba(79, 157, 255, 0.35);
}
/* Pulsante "torna al menu": in alto a sinistra (l'uscita resta a destra). */
.menu-back {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 61;
  padding: 9px 16px;
  font-size: 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  cursor: pointer;
}
.menu-back:hover { background: rgba(255, 255, 255, 0.26); }

/* Presentazione sfogliabile */
.slideshow {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(92vw, 1100px);
  margin: 0 auto;
}
.slideshow .slide {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.6);
}
.slide-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 54px; height: 54px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);   /* colonna frecce meno opaca */
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease;
}
.slide-arrow:hover { background: rgba(255, 255, 255, 0.16); }
.slide-arrow.prev { left: 10px; }
.slide-arrow.next { right: 10px; }
.slide-counter {
  position: absolute;
  bottom: -32px; left: 50%;
  transform: translateX(-50%);
  color: #cdd9ec;
  font-size: 14px;
  letter-spacing: 1px;
}

/* --- Adattamenti mobile per il modal di contenuto --- */
@media (max-width: 640px) {
  #enter-title { font-size: 22px; margin-bottom: 16px; }
  #enter-content { width: 100%; padding: 0 8px; }
  .enter-menu { width: 92vw; gap: 12px; }
  .menu-btn { padding: 16px 18px; font-size: 16px; }
  .slideshow { width: 96vw; }
  .slideshow .slide { max-height: 66vh; }
  .slide-arrow { width: 46px; height: 46px; font-size: 20px; }
  .slide-arrow.prev { left: 4px; }
  .slide-arrow.next { right: 4px; }
  #enter-back, .menu-back { top: 12px; }
  #enter-back { right: 12px; }
  .menu-back { left: 12px; }
}

/* Pulsante di uscita: icona "porta", sempre in alto a sinistra. */
#enter-back {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 60;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 10px;
  cursor: pointer;
}
#enter-back:hover { background: rgba(255, 255, 255, 0.24); }

/* =========================================================
   Editor di scena (tasto K)
   ========================================================= */
#editor-panel {
  position: fixed;
  top: 18px; left: 18px;
  z-index: 30;
  width: 260px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(14, 20, 28, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e7eef8;
  font-size: 13px;
  backdrop-filter: blur(8px);
}
#editor-panel.hidden { display: none; }
#editor-panel hr { border: none; border-top: 1px solid rgba(255,255,255,0.12); margin: 12px 0; }
.ed-head { font-weight: 700; font-size: 15px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: baseline; }
.ed-hint { font-weight: 400; font-size: 11px; color: #8fa3bd; }
.ed-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.ed-row2 { display: flex; gap: 8px; }
.ed-row2 label { flex: 1; }
#editor-panel select, #editor-panel input {
  width: 100%; padding: 6px 8px; border-radius: 8px;
  background: #1b2735; color: #e7eef8; border: 1px solid rgba(255,255,255,0.15);
}
#editor-panel label { display: block; margin: 6px 0; color: #cdd9ec; }
#editor-panel button {
  padding: 8px 10px; border: none; border-radius: 9px; cursor: pointer;
  background: rgba(255,255,255,0.12); color: #fff; font-size: 13px;
}
#editor-panel button:hover { background: rgba(255,255,255,0.22); }
#editor-panel .ed-primary { width: 100%; background: #2f6fd0; font-weight: 600; }
#editor-panel .ed-primary:hover { background: #3a82ef; }
.ed-btns { display: flex; gap: 8px; margin-top: 8px; }
.ed-btns button { flex: 1; }
#ed-del { background: rgba(200,60,60,0.35); }
#ed-del:hover { background: rgba(200,60,60,0.55); }
#ed-selinfo { color: #9fb6da; font-weight: 600; margin-bottom: 6px; }
.ed-tip { font-size: 11px; color: #8fa3bd; margin-top: 8px; line-height: 1.4; }
#ed-preview {
  width: 100%; height: 150px;
  margin: 8px 0;
  border-radius: 10px;
  background: radial-gradient(circle at 50% 40%, #2a3646, #131a24);
  border: 1px solid rgba(255,255,255,0.12);
}
#editor-panel select[size] { height: auto; }

/* =========================================================
   Info point (badge "I" + pannello contatti)
   ========================================================= */
#infopoint-badge {
  position: fixed;
  z-index: 12;
  display: none;
  transform: translate(-50%, -50%);
  width: 54px; height: 54px;
  align-items: center; justify-content: center;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700; font-size: 30px; font-style: italic;
  color: #fff;
  background: radial-gradient(circle at 35% 30%, #4fb0ff, #1f6fd0);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 4px 14px rgba(31, 111, 208, 0.6);
  cursor: pointer;
  pointer-events: auto;
  animation: ip-bob 1.6s ease-in-out infinite;
}
@keyframes ip-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -8px; }
}

/* =========================================================
   Esperto StraTech: etichetta fluttuante sul salottino + richiesta Sì/No
   ========================================================= */
#expert-badge {
  position: fixed;
  z-index: 12;
  display: none;
  transform: translate(-50%, -50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, #356cb6, #1f4f8f);
  color: #fff;
  font-family: "Poppins", system-ui, -apple-system, sans-serif;
  font-weight: 600; font-size: 14px;
  white-space: nowrap;
  border: 2px solid #fff;
  box-shadow: 0 8px 20px rgba(31, 111, 208, 0.5);
  cursor: pointer; pointer-events: auto;
  animation: ip-bob 1.8s ease-in-out infinite;
}
#expert-panel {
  position: fixed;
  z-index: 14;
  left: 50%; bottom: 92px;
  transform: translateX(-50%) translateY(18px);
  display: none; opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.3);
  text-align: center;
  max-width: 90vw;
  font-family: "Poppins", system-ui, -apple-system, sans-serif;
}
#expert-panel.show { display: block; opacity: 1; transform: translateX(-50%) translateY(0); }
.exp-text { font-size: 16px; font-weight: 600; color: #16222e; margin-bottom: 16px; }
.exp-btns { display: flex; gap: 12px; justify-content: center; }
.exp-btns button {
  font-family: inherit; font-weight: 600; font-size: 15px;
  padding: 10px 28px; border-radius: 11px; border: none; cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.exp-btns button:active { transform: scale(0.96); }
.exp-yes { background: #1f6fd0; color: #fff; }
.exp-yes:hover { filter: brightness(1.08); }
.exp-no { background: #e6eaef; color: #444; }

#infopoint-panel {
  position: fixed;
  z-index: 13;
  top: 50%; right: 24px;
  transform: translateY(-50%) translateX(20px);
  width: 290px;
  padding: 18px 20px;
  border-radius: 16px;
  background: rgba(12, 18, 26, 0.92);
  border: 1px solid rgba(120, 180, 255, 0.4);
  color: #e7eef8;
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
#infopoint-panel.show { opacity: 1; transform: translateY(-50%) translateX(0); pointer-events: auto; }
#infopoint-panel { display: flex; flex-direction: column; }
.ip-title { order: 0; }
#chat-messages { order: 1; position: relative; }
#chat-form { order: 2; }
.ip-title {
  font-size: 16px; font-weight: 700; color: #fff;
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

/* Chat dell'assistente (robot) */
#chat-messages {
  height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  margin-bottom: 10px;
}
.chat-msg {
  max-width: 85%;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg.user { align-self: flex-end; background: #2f6fd0; color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.bot { align-self: flex-start; background: rgba(255,255,255,0.10); color: #e7eef8; border-bottom-left-radius: 4px; }
.chat-msg.bot.typing { opacity: 0.6; }

#chat-form { display: flex; gap: 8px; }
#chat-input {
  flex: 1;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 13px;
}
#chat-input::placeholder { color: #8fa3bd; }
#chat-send {
  width: 40px; border: none; border-radius: 10px;
  background: #2f6fd0; color: #fff; font-size: 15px; cursor: pointer;
}
#chat-send:hover { background: #3a82ef; }

@media (max-width: 640px) {
  #infopoint-panel { right: 12px; left: 12px; width: auto; top: 12px; transform: none; }
  #infopoint-panel.show { transform: none; }
  #chat-messages { height: 46vh; }
  /* Box di scrittura in ALTO su mobile (resta visibile sopra la tastiera). */
  #chat-form { order: 1; margin-bottom: 10px; }
  #chat-messages { order: 2; }
}

/* =========================================================
   Fumetto del poliziotto
   ========================================================= */
#speech-bubble {
  position: fixed;
  z-index: 9;
  display: none;               /* mostrato da JS quando in vista */
  transform: translate(-50%, -100%);
  max-width: 220px;
  padding: 9px 13px;
  background: #ffffff;
  color: #14202e;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  border-radius: 14px;
  border: 2px solid #1f3550;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  white-space: nowrap;
}
/* Codina del fumetto */
#speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  border-width: 9px 7px 0 7px;
  border-style: solid;
  border-color: #1f3550 transparent transparent transparent;
}
