* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #050707;
  font-family: Arial, Helvetica, sans-serif;
  color: white;
}

canvas {
  display: block;
}

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #050707;
  z-index: 100;
  font-size: 18px;
}

#startScreen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .72);
  backdrop-filter: blur(7px);
  z-index: 50;
}

.card {
  width: min(520px, 90vw);
  text-align: center;
  padding: 34px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 18px;
  background: rgba(5,12,12,.90);
  box-shadow: 0 20px 80px rgba(0,0,0,.45);
}

.card h1 {
  margin: 0 0 8px;
  letter-spacing: .12em;
  font-size: clamp(24px, 5vw, 42px);
}

.card p {
  opacity: .72;
  margin-bottom: 26px;
}

.card small {
  display: block;
  margin-top: 18px;
  opacity: .65;
  line-height: 1.5;
}

button, input {
  font: inherit;
}

button {
  cursor: pointer;
}

#startButton {
  border: 1px solid rgba(255,255,255,.45);
  background: white;
  color: black;
  font-weight: 700;
  padding: 14px 22px;
  border-radius: 10px;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.brand {
  position: absolute;
  top: 18px;
  left: 20px;
  font-size: 12px;
  letter-spacing: .15em;
  opacity: .75;
}

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  opacity: .8;
}

#interaction {
  position: absolute;
  left: 50%;
  bottom: 38px;
  transform: translateX(-50%);
  background: rgba(0,0,0,.68);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  min-height: 16px;
  white-space: nowrap;
}

#panel,
#npcChat {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.68);
  z-index: 60;
}

.hidden {
  display: none !important;
}

.panel-card,
.chat-card {
  position: relative;
  width: min(650px, 92vw);
  border-radius: 18px;
  background: #0b1111;
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: 0 20px 70px rgba(0,0,0,.5);
}

.panel-card {
  padding: 30px;
}

.panel-card h2 {
  margin-top: 0;
  letter-spacing: .08em;
}

.panel-card p {
  color: rgba(255,255,255,.78);
  line-height: 1.65;
}

.close-ui {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  font-size: 22px;
}

.panel-card .close-ui {
  position: absolute;
  top: 12px;
  right: 14px;
}

.chat-card {
  overflow: hidden;
}

.chat-header {
  min-height: 72px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,.12);
  background: #101a1a;
}

.chat-header strong {
  display: block;
  letter-spacing: .12em;
}

.chat-header span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  opacity: .65;
}

.chat-messages {
  height: min(400px, 48vh);
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 82%;
  padding: 11px 13px;
  border-radius: 13px;
  line-height: 1.45;
  font-size: 14px;
}

.msg.npc {
  align-self: flex-start;
  background: #172727;
  border: 1px solid rgba(255,255,255,.08);
}

.msg.user {
  align-self: flex-end;
  background: white;
  color: #111;
}

.suggestions {
  padding: 0 18px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggestions button {
  border: 1px solid rgba(255,255,255,.18);
  background: transparent;
  color: white;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.chat-form {
  display: flex;
  gap: 10px;
  padding: 16px 18px 18px;
  border-top: 1px solid rgba(255,255,255,.10);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(255,255,255,.16);
  background: #070b0b;
  color: white;
  border-radius: 10px;
  padding: 12px 13px;
  outline: none;
}

.chat-form button {
  border: 0;
  background: white;
  color: black;
  padding: 0 18px;
  border-radius: 10px;
  font-weight: 700;
}

@media (max-width: 600px) {
  .suggestions {
    display: none;
  }

  .chat-form {
    flex-direction: column;
  }

  .chat-form button {
    padding: 12px;
  }
}

/* =========================================================
   MOBILE-FIRST CONTROLS v0.4
   ========================================================= */
body, canvas {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

.mobile-help,
#mobileControls {
  display: none;
}

#mobileControls {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.joystick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 124px;
  height: 124px;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}

.joystick-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.28);
  background: rgba(0,0,0,.22);
  box-shadow: inset 0 0 28px rgba(255,255,255,.04);
  backdrop-filter: blur(2px);
}

.joystick-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(0,0,0,.25);
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}

.mobile-action {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(30px, env(safe-area-inset-bottom));
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.45);
  background: rgba(255,255,255,.88);
  color: #050707;
  font-weight: 900;
  font-size: 24px;
  pointer-events: auto;
  touch-action: manipulation;
  box-shadow: 0 8px 28px rgba(0,0,0,.35);
}

#lookHint {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 96px);
  font-size: 11px;
  opacity: .46;
  letter-spacing: .06em;
  pointer-events: none;
}

@media (pointer: coarse), (max-width: 900px) {
  .desktop-help { display: none !important; }
  .mobile-help { display: block; }

  #mobileControls.mobile-enabled { display: block; }

  .brand {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    font-size: 10px;
  }

  #crosshair {
    font-size: 18px;
    opacity: .55;
  }

  #interaction {
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 104px);
    max-width: 72vw;
    white-space: normal;
    text-align: center;
    font-size: 12px;
    padding: 8px 10px;
  }

  .card {
    width: min(92vw, 520px);
    padding: 24px 20px;
    border-radius: 16px;
  }

  #startButton {
    width: 100%;
    min-height: 48px;
  }

  #panel,
  #npcChat {
    align-items: stretch;
  }

  .panel-card,
  .chat-card {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .panel-card {
    padding: calc(58px + env(safe-area-inset-top)) 22px calc(22px + env(safe-area-inset-bottom));
  }

  .panel-card .close-ui {
    top: calc(12px + env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
  }

  .chat-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .chat-header {
    padding-top: calc(14px + env(safe-area-inset-top));
    flex: 0 0 auto;
  }

  .chat-messages {
    height: auto;
    min-height: 0;
    flex: 1 1 auto;
  }

  .suggestions {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 10px;
  }

  .suggestions button {
    flex: 0 0 auto;
  }

  .chat-form {
    flex-direction: row;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .chat-form button {
    padding: 0 16px;
  }
}

@media (pointer: coarse) and (orientation: landscape) {
  .joystick {
    width: 112px;
    height: 112px;
  }

  .mobile-action {
    width: 64px;
    height: 64px;
  }

  #lookHint {
    display: none;
  }
}


/* =========================================================
   MULTIPLAYER TESTUALE v0.5 — MOBILE FIRST
   ========================================================= */
.player-name-input {
  width: min(100%, 320px);
  box-sizing: border-box;
  min-height: 48px;
  margin: 8px auto 12px;
  padding: 0 14px;
  border: 1px solid rgba(102,187,106,.42);
  border-radius: 12px;
  outline: none;
  background: #001110;
  color: #fff;
  font-size: 17px;
  text-align: center;
}
.player-name-input:focus {
  border-color: #66bb6a;
  box-shadow: 0 0 0 3px rgba(102,187,106,.10);
}
.multiplayer-status {
  display: block;
  margin-top: 9px;
  color: #a9c9ae;
  font-size: 12px;
}

.world-chat-toggle {
  position: fixed;
  z-index: 120;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  min-width: 74px;
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 13px;
  background: #66bb6a;
  color: #001110;
  font-weight: 900;
  box-shadow: 0 8px 28px rgba(0,0,0,.38);
}
.world-chat-toggle.hidden { display: none; }

.world-chat-panel {
  position: fixed;
  z-index: 140;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: none;
  flex-direction: column;
  height: min(54vh, 440px);
  overflow: hidden;
  border: 1px solid rgba(102,187,106,.38);
  border-radius: 16px;
  background: rgba(0,17,16,.97);
  box-shadow: 0 18px 55px rgba(0,0,0,.50);
}
.world-chat-panel.open { display: flex; }

.world-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 12px;
  background: #113a32;
  color: #fff;
  font-weight: 900;
}
#worldOnlineCount {
  margin-left: auto;
  color: #bddbc2;
  font-size: 12px;
  font-weight: 600;
}
#worldChatClose {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.world-chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  color: #edf8ef;
  font-size: 14px;
  line-height: 1.38;
}
.world-chat-message {
  margin: 0 0 9px;
  overflow-wrap: anywhere;
}
.world-chat-message .world-chat-name {
  color: #66bb6a;
  font-weight: 900;
}
.world-chat-message.system {
  color: #9fb8a4;
  font-style: italic;
}

.world-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(102,187,106,.18);
}
.world-chat-form input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid rgba(102,187,106,.32);
  border-radius: 11px;
  outline: none;
  background: #001110;
  color: #fff;
  font-size: 16px;
}
.world-chat-form input:focus { border-color: #66bb6a; }
.world-chat-form button {
  min-width: 68px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: #66bb6a;
  color: #001110;
  font-weight: 900;
}

@media (min-width: 760px) {
  .world-chat-panel {
    left: auto;
    right: 18px;
    width: 380px;
    height: 440px;
  }
}


/* =========================================================
   CHAT/HUD v0.5.2
   ========================================================= */
.world-status-bar {
  position: fixed;
  z-index: 135;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 5px 7px 5px 11px;
  border: 1px solid rgba(102,187,106,.38);
  border-radius: 999px;
  background: rgba(0,17,16,.90);
  color: #eaf7ec;
  box-shadow: 0 8px 26px rgba(0,0,0,.32);
  backdrop-filter: blur(8px);
  font-size: 13px;
}
.world-status-bar.hidden { display: none; }

.world-status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #66bb6a;
  box-shadow: 0 0 9px rgba(102,187,106,.72);
}

.world-status-chat {
  position: relative;
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: #66bb6a;
  color: #001110;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.world-unread-badge {
  position: absolute;
  top: -8px;
  right: -7px;
  display: grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  padding: 0 4px;
  border-radius: 999px;
  background: #fff;
  color: #001110;
  font-size: 11px;
  font-weight: 900;
  box-shadow: 0 3px 10px rgba(0,0,0,.35);
}
.world-unread-badge.hidden { display: none; }

.world-chat-toast {
  position: fixed;
  z-index: 150;
  top: max(62px, calc(env(safe-area-inset-top) + 52px));
  right: max(12px, env(safe-area-inset-right));
  width: min(82vw, 330px);
  padding: 10px 12px;
  border: 1px solid rgba(102,187,106,.38);
  border-radius: 12px;
  background: rgba(0,17,16,.96);
  color: #edf8ef;
  box-shadow: 0 10px 32px rgba(0,0,0,.45);
  font-size: 13px;
  line-height: 1.35;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.world-chat-toast.hidden {
  opacity: 0;
  transform: translateY(-7px);
  visibility: hidden;
}
.world-chat-toast:not(.hidden) {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

/* Il vecchio bottone flottante della v0.5 non viene più usato */
.world-chat-toggle { display: none !important; }

/* Desktop: chat laterale persistente quando aperta */
@media (min-width: 760px) and (pointer: fine) {
  .world-chat-panel {
    top: 64px;
    right: 16px;
    bottom: 16px;
    left: auto;
    width: min(360px, 30vw);
    height: auto;
    max-height: calc(100vh - 80px);
  }

  .world-chat-panel.open {
    display: flex;
  }

  .world-chat-messages {
    background: rgba(0,17,16,.72);
  }
}


/* =========================================================
   v0.5.3 — CHAT SHORTCUTS + GRANDE SALA
   ========================================================= */
.world-status-chat[title*="silenziata"] {
  opacity: .72;
}

@media (min-width: 760px) and (pointer: fine) {
  /* La chat resta laterale quando aperta, ma non viene più aperta automaticamente. */
  .world-chat-panel.open {
    display: flex;
  }
}


/* =========================================================
   v0.5.4 — CHAT PRIVATA DI PROSSIMITÀ
   ========================================================= */
.private-chat-panel {
  position: fixed;
  inset: 0;
  z-index: 175;
  display: grid;
  place-items: end center;
  padding:
    12px
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  background: rgba(0,17,16,.22);
  pointer-events: none;
}
.private-chat-panel.hidden { display: none; }

.private-chat-card {
  pointer-events: auto;
  width: min(100%, 520px);
  max-height: min(58vh, 520px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(0,182,122,.5);
  border-radius: 16px;
  background: rgba(0,17,16,.97);
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
}

.private-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 12px;
  background: #113a32;
  color: #fff;
}
.private-chat-header > div {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.private-chat-header strong {
  color: #66bb6a;
  font-size: 12px;
  letter-spacing: .08em;
}
.private-chat-header span {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 900;
}
#privateChatClose {
  margin-left: auto;
  width: 38px;
  height: 38px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 29px;
  line-height: 1;
  cursor: pointer;
}

.private-chat-messages {
  flex: 1;
  min-height: 130px;
  overflow-y: auto;
  padding: 12px;
  color: #eef9f0;
  font-size: 14px;
}
.private-msg {
  max-width: 86%;
  margin: 0 0 9px;
  padding: 8px 10px;
  border-radius: 12px;
  overflow-wrap: anywhere;
}
.private-msg.remote {
  margin-right: auto;
  background: #113a32;
}
.private-msg.own {
  margin-left: auto;
  background: #1c503f;
}
.private-msg.system {
  max-width: 100%;
  margin-inline: auto;
  padding: 4px 0;
  background: transparent;
  color: #9fb8a4;
  font-style: italic;
  text-align: center;
}

.private-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(102,187,106,.18);
}
.private-chat-form input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  box-sizing: border-box;
  padding: 0 12px;
  border: 1px solid rgba(102,187,106,.36);
  border-radius: 11px;
  outline: none;
  background: #001110;
  color: #fff;
  font-size: 16px;
}
.private-chat-form input:focus {
  border-color: #66bb6a;
}
.private-chat-form button {
  min-width: 72px;
  min-height: 46px;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: #66bb6a;
  color: #001110;
  font-weight: 900;
  cursor: pointer;
}

@media (min-width: 760px) and (pointer: fine) {
  .private-chat-panel {
    place-items: center;
  }
  .private-chat-card {
    width: 460px;
    max-height: 480px;
  }
}




/* v0.5.6 - il riquadro interazione esiste solo quando c'è testo */
#interaction:empty {
  display: none;
}


/* =========================================================
   v0.6.3 — ACCESSO OBBLIGATORIO + VM18
   ========================================================= */
.age-gate {
  width: min(100%, 320px);
  margin: 2px auto 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  border: 1px solid rgba(102,187,106,.28);
  border-radius: 11px;
  background: rgba(0,17,16,.62);
  color: #e9f7eb;
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}
.age-gate input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  accent-color: #66bb6a;
}
.age-gate.gate-error {
  border-color: rgba(255,105,105,.78);
  box-shadow: 0 0 0 2px rgba(255,105,105,.10);
}
.player-name-input.input-error {
  border-color: rgba(255,105,105,.82);
  box-shadow: 0 0 0 3px rgba(255,105,105,.10);
}
.entry-error {
  display: block;
  min-height: 18px;
  margin: 0 auto 9px !important;
  color: #ff9c9c;
  opacity: 1 !important;
  font-size: 12px;
  font-weight: 700;
}
#startButton:disabled {
  opacity: .42;
  cursor: not-allowed;
}


/* =========================================================
   v0.7.1 — ACCOUNT OTP + LOGIN + GUEST
   ========================================================= */
.auth-card {
  width: min(560px, 94vw);
  max-height: min(94vh, 760px);
  overflow-y: auto;
  padding: 26px 22px;
}
.auth-tabs {
  width: min(100%, 390px);
  margin: 0 auto 17px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}
.auth-tab {
  min-height: 42px;
  padding: 0 8px;
  border: 1px solid rgba(102,187,106,.28);
  border-radius: 10px;
  background: rgba(0,17,16,.72);
  color: #dceee0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .035em;
}
.auth-tab.active {
  background: #66bb6a;
  color: #001110;
  border-color: #66bb6a;
}
.auth-panel {
  width: 100%;
}
.auth-action {
  width: min(100%, 320px);
  min-height: 46px;
  margin: 2px auto 9px;
  padding: 0 14px;
  border: 1px solid rgba(102,187,106,.55);
  border-radius: 11px;
  background: #66bb6a;
  color: #001110;
  font-weight: 900;
}
.auth-action:disabled {
  opacity: .42;
  cursor: not-allowed;
}
.auth-action.busy {
  opacity: .62;
  cursor: wait;
}
.auth-code-step {
  width: 100%;
  margin-top: 7px;
}
.auth-info {
  display: block;
  width: min(100%, 320px);
  margin: 3px auto 7px !important;
  color: #b9d9be;
  opacity: 1 !important;
  font-size: 12px;
  line-height: 1.4;
}
.otp-input {
  letter-spacing: .20em;
  font-weight: 800;
}
.guest-note {
  width: min(100%, 320px);
  margin: 0 auto 8px !important;
  color: #b8d4bc;
  font-size: 12px;
  line-height: 1.4;
  opacity: .9 !important;
}
@media (max-width: 520px) {
  .auth-card {
    padding: 20px 14px;
    border-radius: 14px;
  }
  .auth-tab {
    font-size: 11px;
    padding-inline: 4px;
  }
}


/* =========================================================
   v0.7.4 — sessione attiva / rientro rapido
   ========================================================= */
.resume-panel {
  text-align: center;
}
.resume-title {
  margin: 4px 0 2px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: #66bb6a;
}
.resume-user {
  margin: 6px 0 14px;
  color: #fff;
  font-size: 17px;
}
.resume-user strong {
  color: #9fe5aa;
}
