/* Touch-Steuerung (nur mit body.touch-device, siehe MobileControls).
   Aufteilung: rechts steuern (Daumen), links handeln. Farben und Knopf-Stil
   stehen in hud.css. */

#mobile-controls {
  display: none;
}

body.touch-device #mobile-controls {
  display: block;
}

/* Steuerfeld: rechte untere Bildschirmhälfte. Der Stick erscheint dort, wo
   der Daumen aufsetzt; der Ring in Ruhe zeigt nur, wo das Feld ist. */
#joystick-zone {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 58vw;
  height: 46vh;
  z-index: 1500;
  touch-action: none;
}

#joystick-idle {
  position: absolute;
  right: calc(28px + env(safe-area-inset-right));
  bottom: calc(40px + env(safe-area-inset-bottom));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px dashed rgba(246, 234, 206, 0.28);
  background: radial-gradient(circle, rgba(246, 234, 206, 0.10) 0 26px, transparent 27px);
  pointer-events: none;
  transition: opacity 0.2s;
}

#joystick-zone.is-active #joystick-idle {
  opacity: 0;
}

#joystick-base {
  display: none;
  position: absolute;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 3px solid rgba(246, 234, 206, 0.55);
  background: rgba(24, 33, 27, 0.35);
  box-shadow: 0 0 0 2px rgba(34, 26, 18, 0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#joystick-thumb {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--brass);
  border: 3px solid var(--ink);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Handeln: unten links, großer Aktionsknopf + Beutel */
#action-cluster {
  position: fixed;
  left: calc(18px + env(safe-area-inset-left));
  bottom: calc(26px + env(safe-area-inset-bottom));
  z-index: 1500;
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

#mobile-btn-inventory {
  order: 2;
  margin-bottom: 44px;
}

/* ── Übersteuerungen fürs Handy ────────────────────── */

body.touch-device #instructions {
  display: none !important;
}

/* Chat: eingeklappt stehen die letzten Nachrichten durchlässig unter der
   Minikarte (samt überstehendem Heimkehr-Knopf, +14 px); Eingabe nur über
   Menü → Chat (dann als Blatt oben). Fest verdrahtete 200 px rutschten unter
   die Minikarte, als die Statusbox wuchs (Playtest 28.09.). */
body.touch-device #chat-container {
  bottom: auto;
  top: calc(var(--hud-bottom) + var(--minimap) + 14px);
  left: 8px;
  right: auto;
  width: min(250px, calc(100% - 100px));
  max-height: 110px;
  transform: none;
  border: none;
  box-shadow: none;
  background: transparent;
  pointer-events: none;
}

body.touch-device #chat-messages {
  max-height: 66px;
  padding: 0;
  font-size: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

/* Eingeklappt: jede Zeile als kleines, halbdurchsichtiges Schild (lesbar auf
   hellem Gras), ohne Uhrzeit; alte Zeilen blendet ChatUI aus (.is-old) */
body.touch-device #chat-container:not(.chat-open) .chat-message {
  align-self: flex-start;
  max-width: 100%;
  margin: 0 0 3px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(13, 19, 15, 0.55);
  line-height: 1.35;
  text-shadow: 0 1px 0 #000;
  transition: opacity 0.6s;
}

body.touch-device #chat-container:not(.chat-open) .chat-time {
  display: none;
}

body.touch-device #chat-container:not(.chat-open) .chat-message.is-fading {
  opacity: 0;
}

body.touch-device #chat-container:not(.chat-open) .chat-message.is-old {
  display: none;
}

body.touch-device #chat-input-container {
  display: none;
  padding: 6px;
}

body.touch-device #chat-container.chat-open {
  top: calc(8px + env(safe-area-inset-top));
  left: 8px;
  width: calc(100% - 16px);
  max-height: none;
  pointer-events: auto;
  z-index: 2600;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--brass-dark), 0 4px 0 rgba(0, 0, 0, 0.35);
}

body.touch-device #chat-container.chat-open #chat-messages {
  max-height: 130px;
  padding: 6px 8px;
  overflow-y: auto;
  display: block;
}

body.touch-device #chat-container.chat-open #chat-input-container {
  display: flex;
}

body.touch-device #chat-input {
  font-size: 16px; /* unter 16px zoomt der Browser beim Fokus die Seite */
}

/* Angepinnte Quests: auf dem Handy schmal rechts, auf Höhe der Minikarte —
   unter der Statusbox, sonst überdeckt die Leiste deren rechte Ecke */
body.touch-device #quest-tracker {
  top: var(--hud-bottom);
  right: 8px;
  width: min(190px, calc(100% - 16px));
  padding: 8px 10px;
}

/* Fenster (Inventar, Laden, Quest): ans Handy anpassen */
body.touch-device #inventory-container,
body.touch-device #shop-container,
body.touch-device #quest-container,
body.touch-device #crafting-container {
  width: calc(100% - 16px);
  max-width: 420px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 10px;
}
