/* Virtual sticks and action buttons for touch screens. */
.touch-ui {
  position: fixed; inset: 0; z-index: 6;
  pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .18s ease;
  /* Base stick diameter; SIZE in the controls menu scales these two values. */
  --stickBase: 122px;
  --stickScale: 1;
  --pad: 20px;
}
body.game-active .touch-ui { opacity: 1; visibility: visible; }
.pause:not(.hidden) ~ .touch-ui { opacity: 0; visibility: hidden; }

.stick-wrap {
  position: absolute;
  bottom: calc(var(--safe-bottom) + var(--pad));
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.stick-wrap.move { left: calc(var(--safe-left) + var(--pad)); }
.stick-wrap.aim { right: calc(var(--safe-right) + var(--pad)); }
body.touch-capable.game-active .stick-wrap { pointer-events: auto; }
.stick {
  position: relative;
  width: calc(var(--stickBase) * var(--stickScale));
  height: calc(var(--stickBase) * var(--stickScale));
  border-radius: 50%;
  border: 1px solid rgba(140, 210, 255, .2);
  background:
    radial-gradient(circle at 50% 50%, rgba(10, 26, 22, .42), rgba(4, 10, 9, .18) 72%, transparent 74%);
  box-shadow: inset 0 0 34px rgba(0, 0, 0, .5);
  touch-action: none;
}
.stick::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 96%, rgba(191, 255, 216, .1) 98%, transparent 100%);
  opacity: .5; pointer-events: none;
}
.stick-wrap.aim .stick { border-color: rgba(77, 255, 155, .22); }
.stick.active { border-color: rgba(140, 210, 255, .7); box-shadow: inset 0 0 34px rgba(0, 0, 0, .5), 0 0 22px rgba(108, 204, 255, .12); }
.stick-wrap.aim .stick.active { border-color: rgba(77, 255, 155, .8); box-shadow: inset 0 0 34px rgba(0, 0, 0, .5), 0 0 22px rgba(77, 255, 155, .16); }
.stick-ring { position: absolute; inset: 15%; border-radius: 50%; border: 1px dashed rgba(255, 255, 255, .07); }
.stick-knob {
  position: absolute; left: 50%; top: 50%;
  width: calc(var(--stickBase) * var(--stickScale) * .44);
  height: calc(var(--stickBase) * var(--stickScale) * .44);
  margin: calc(var(--stickBase) * var(--stickScale) * -.22) 0 0 calc(var(--stickBase) * var(--stickScale) * -.22);
  border-radius: 50%;
  background: radial-gradient(circle at 36% 30%, rgba(226, 255, 240, .4), rgba(77, 255, 155, .16) 52%, rgba(5, 14, 10, .92));
  border: 1px solid rgba(77, 255, 155, .55);
  box-shadow: 0 0 20px rgba(77, 255, 155, .2);
  transition: transform .1s ease-out;
  pointer-events: none;
}
.stick-wrap.aim .stick-knob { border-color: rgba(140, 210, 255, .65); box-shadow: 0 0 20px rgba(108, 204, 255, .22); }
.stick.active .stick-knob { transition: none; }
.stick-label {
  font: 600 9px/1 var(--mono); letter-spacing: .2em;
  color: rgba(191, 255, 216, .5);
  text-shadow: 0 1px 6px rgba(0, 0, 0, .8);
}

/* Touch buttons sit above the aim stick by default, or above the move stick
   when the player picks the left-handed layout. */
.touch-buttons {
  position: absolute;
  right: calc(var(--safe-right) + var(--pad));
  bottom: calc(var(--safe-bottom) + var(--pad) + (var(--stickBase) * var(--stickScale)) + 30px);
  display: grid; grid-template-columns: repeat(2, 58px); gap: 8px;
}
body.touch-capable.game-active .touch-buttons { pointer-events: auto; }
.touch-buttons button {
  width: 58px; height: 48px; border-radius: 6px;
  background: rgba(4, 14, 11, .68);
  border: 1px solid rgba(77, 255, 155, .3);
  color: #bfffd8;
  font: 700 9px/1 var(--display); letter-spacing: .1em;
  cursor: pointer; touch-action: none;
  -webkit-user-select: none; user-select: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}
.touch-buttons button.pressed { background: rgba(77, 255, 155, .26); border-color: #7dffb0; color: #fff; }
.touch-buttons button.cooling { opacity: .38; }
.touch-buttons #tPause { font-size: 12px; letter-spacing: 0; }
.touch-buttons #tSurge.ready {
  border-color: #ffe15a; color: #fff6b0;
  box-shadow: 0 0 18px rgba(255, 225, 90, .5);
  animation: surgeReady 1.1s ease-in-out infinite;
}
@keyframes surgeReady {
  50% { border-color: #fff2a0; box-shadow: 0 0 30px rgba(255, 225, 90, .8); }
}

/* SIZE preference */
body.stick-s .touch-ui { --stickScale: .82; }
body.stick-l .touch-ui { --stickScale: 1.14; }

/* LEFT preference: mirror sticks and buttons without mirroring the labels. */
body.sticks-left .stick-wrap.move { left: auto; right: calc(var(--safe-right) + var(--pad)); }
body.sticks-left .stick-wrap.aim { right: auto; left: calc(var(--safe-left) + var(--pad)); }
body.sticks-left .touch-buttons { right: auto; left: calc(var(--safe-left) + var(--pad)); }

@media (max-width: 760px) {
  .touch-ui { --stickBase: 108px; --pad: 14px; }
  .touch-buttons { grid-template-columns: repeat(2, 54px); gap: 7px; }
  .touch-buttons button { width: 54px; height: 45px; }
}

/* Landscape phones: smaller rings, buttons stay above the aim stick. */
@media (max-height: 500px) {
  .touch-ui { --stickBase: 92px; --pad: 12px; }
  .stick-label { font-size: 8px; letter-spacing: .16em; }
  .touch-buttons {
    grid-template-columns: repeat(2, 52px);
    gap: 6px;
    bottom: calc(var(--safe-bottom) + var(--pad) + (var(--stickBase) * var(--stickScale)) + 26px);
  }
  .touch-buttons button { width: 52px; height: 42px; }
}

/* Short landscape with a very narrow viewport (folded phones). */
@media (max-height: 380px) and (max-width: 720px) {
  .touch-ui { --stickBase: 84px; }
  .touch-buttons { grid-template-columns: repeat(2, 48px); }
  .touch-buttons button { width: 48px; height: 38px; }
}
