/* Nusa Island touch layer. Sits above the canvas (z 0) and below #ui (z 10). */

.touch-layer, .rotate-hint {
  --signal: #FF5B1F;
  --signal-ink: #1B0E06;
  --hud: #F4EFE3;
  --disc: rgba(23, 20, 15, .46);
  --f-label: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --f-display: 'Big Shoulders Stencil Display', 'Impact', 'Arial Narrow', sans-serif;
  --sl: max(16px, env(safe-area-inset-left, 0px));
  --sr: max(16px, env(safe-area-inset-right, 0px));
  --sb: max(16px, env(safe-area-inset-bottom, 0px));
  --st: max(12px, env(safe-area-inset-top, 0px));
}

.touch-layer {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: auto;
  overflow: hidden;
}
.touch-layer.is-hidden { display: none; }
.touch-layer, .touch-layer *, .rotate-hint {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

/* ---------- Stick ---------- */
.tc-stick {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  pointer-events: none;
  will-change: transform;
}
.tc-stick.is-rest {
  left: calc(var(--sl) + 76px);
  bottom: calc(var(--sb) + 56px);
  top: auto;
}
.tc-base, .tc-knob { position: absolute; border-radius: 50%; }
.tc-base {
  width: 128px; height: 128px; left: -64px; top: -64px;
  border: 2px dashed rgba(244, 239, 227, .55);
  background: rgba(23, 20, 15, .28);
  opacity: .5;
  transition: opacity .12s linear;
}
.tc-knob {
  width: 56px; height: 56px; left: -28px; top: -28px;
  background: rgba(244, 239, 227, .5);
  box-shadow: inset 0 0 0 2px rgba(23, 20, 15, .55);
  will-change: transform;
}
.tc-stick.is-active .tc-base { opacity: 1; }
.tc-stick.is-active .tc-knob { background: rgba(244, 239, 227, .82); }
.tc-stick.is-sprint .tc-knob { background: var(--signal); }
.tc-stick.is-sprint .tc-base { border-color: var(--signal); }

/* ---------- Buttons ---------- */
.tc-btn {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--disc);
  box-shadow: inset 0 0 0 2px rgba(244, 239, 227, .5);
  color: var(--hud);
  font-family: var(--f-label);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  transition: transform .06s linear, background-color .06s linear, box-shadow .06s linear;
}
.tc-btn.is-down {
  transform: scale(.92);
  background: var(--signal);
  color: var(--signal-ink);
  text-shadow: none;
  box-shadow: inset 0 0 0 2px rgba(27, 14, 6, .5);
}
.tc-btn.is-on {
  background: rgba(255, 91, 31, .85);
  color: var(--signal-ink);
  text-shadow: none;
  box-shadow: inset 0 0 0 2px rgba(27, 14, 6, .5);
}
.tc-ic { display: block; flex: none; }
.tc-lbl { pointer-events: none; }

/* thumb arc (bottom right) */
.tc-fire   { width: 78px; height: 78px; right: var(--sr); bottom: var(--sb); font-size: 13px; }
.tc-aim    { right: calc(var(--sr) + 90px); bottom: calc(var(--sb) + 4px); }
.tc-jump   { width: 56px; height: 56px; right: calc(var(--sr) + 10px); bottom: calc(var(--sb) + 92px); }
.tc-use    { width: 64px; height: 64px; right: calc(var(--sr) + 80px); bottom: calc(var(--sb) + 80px); font-size: 13px; text-align: center; }
.tc-reload { width: 52px; height: 52px; right: calc(var(--sr) + 160px); bottom: calc(var(--sb) + 4px); }
.tc-putback { width: 64px; height: 64px; right: calc(var(--sr) + 10px); bottom: calc(var(--sb) + 4px); border-radius: 14px; font-size: 12px; text-align: center; }
/* USE only exists while there is something to use (aimed at an item, the crate, an examine target);
   hidden it lets the touch fall through to the look area */
.touch-layer:not(.can-interact) .tc-use { opacity: 0; pointer-events: none; transform: scale(.8); }
.touch-layer .tc-use { transition: opacity .14s ease-out, transform .14s ease-out, background-color .06s linear, box-shadow .06s linear; }
.touch-layer.can-interact .tc-use {
  background: rgba(255, 91, 31, .78);
  color: var(--signal-ink);
  text-shadow: none;
  animation: tc-pulse 1.1s ease-in-out infinite;
}
@keyframes tc-pulse {
  0%, 100% { box-shadow: inset 0 0 0 2px rgba(27, 14, 6, .5), 0 0 0 0 rgba(255, 91, 31, .55); }
  50% { box-shadow: inset 0 0 0 2px rgba(27, 14, 6, .5), 0 0 0 9px rgba(255, 91, 31, 0); }
}

/* context visibility */
.tc-aim, .tc-reload, .tc-putback { display: none; }
.touch-layer.has-aim .tc-aim, .touch-layer.has-ak .tc-reload { display: flex; }
.touch-layer.no-fire .tc-fire { display: none; }
.touch-layer.is-examining .tc-putback { display: flex; }
.touch-layer.is-examining .tc-fire, .touch-layer.is-examining .tc-aim,
.touch-layer.is-examining .tc-reload,
.touch-layer.is-examining .tc-jump { display: none; }
.touch-layer.is-examining .tc-use { right: calc(var(--sr) + 10px); bottom: calc(var(--sb) + 80px); width: 72px; height: 72px; }
.touch-layer.is-examining .tc-putback { right: calc(var(--sr) + 90px); bottom: calc(var(--sb) + 8px); }

/* top-right system buttons */
.tc-top { width: 48px; height: 48px; top: var(--st); border-radius: 12px; }
.tc-pause { right: var(--sr); }
.tc-fs    { right: calc(var(--sr) + 56px); }
.tc-inv   { right: calc(var(--sr) + 112px); }
.tc-map   { right: calc(var(--sr) + 168px); } /* Stage 18 */
.tc-chat  { right: calc(var(--sr) + 224px); } /* Stage 22a: rooms only (the layer gets .is-mp) */
.touch-layer:not(.is-mp) .tc-chat { visibility: hidden; pointer-events: none; }
.touch-layer.hl-editing:not(.is-mp) .tc-chat { visibility: visible; }

/* ---------- Rotate hint ---------- */
.rotate-hint {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
  background: #E8E0CC;
  color: #17140F;
  text-align: center;
  pointer-events: auto;
}
.rotate-hint[hidden] { display: none; }
.rh-phone {
  position: relative;
  width: 54px; height: 96px;
  border: 4px solid #17140F;
  border-radius: 10px;
  animation: rh-turn 2.4s cubic-bezier(.16, 1, .3, 1) infinite;
}
.rh-phone i {
  position: absolute; left: 50%; bottom: 6px;
  width: 14px; height: 4px; margin-left: -7px;
  border-radius: 2px; background: var(--signal);
}
.rh-text {
  margin: 0;
  max-width: 14ch;
  font-family: var(--f-display);
  font-weight: 800;
  font-size: 34px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: .02em;
}
@keyframes rh-turn {
  0%, 20% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}
@media (prefers-reduced-motion: reduce) {
  .rh-phone { animation: none; transform: rotate(-90deg); }
  .touch-layer.can-interact .tc-use { animation: none; }
}
